Playwright
Integrating Synpress into Playwright is quite straightforward.
Let’s digest a simple test step by step:
Import
First, you need to import the testWithSynpress
function from @synthetixio/synpress
and use it to define your test
function that you’d typically import directly from Playwright:
The first argument of the testWithSynpress
function is the wallet setup function you want to use in this test file.
The second argument is a function that will be used to unlock the wallet before each test. Currently, you have to pass the unlockForFixture
function from @synthetixio/synpress
which unlocks the MetaMask wallet, but soon you’ll be able to pass here unlock functions from other wallets!
Define your test
Now that you have access to the test
function that you’d typically import from Playwright, you can use it to define your test:
You can notice the unusual extensionId
fixture used here. This fixture is amongst a few others that are provided by Synpress. You can learn more about them in the Built-in Fixtures section.
To access the MetaMask API, you must create an instance of the MetaMask
class as shown above. To learn more about the constructor and all the methods this class provides, see its API reference.
If you’re using the same wallet setup in multiple test files, you can speed up the process of writing your tests by defining a custom fixture that will create the MetaMask
instance for you.
💡 Show details below to see how to do it
Run the test
Now that you have your test defined, you can run it as you would typically do with Playwright:
In the current stage of Synpress development, the playwright test
command will behave differently than you might expect, i.e., it will run in the headed mode by default, similarly to playwright test --headed
.
To run your tests in the headless mode, you need to use the HEADLESS
environmental variable:
This behavior will be changed in the future to resemble Playwright’s default behavior.
Synpress now supports all features of Playwright, including Parallelism and UI Mode!