Playwright
Integrating Synpress into Playwright is quite straightforward.
Let’s digest a simple test step by step:
Import
First, you need to import the necessary modules and setup:
The testWithSynpress
function takes the MetaMask fixtures as an argument, which includes your wallet setup configuration. This setup defines how your wallet should be configured before each test.
Define your test
Now that you have your test instance configured, you can write your test:
The test uses several fixtures provided by Synpress:
context
: Playwright browser contextpage
: The page where your dApp is runningmetamaskPage
: The MetaMask extension pageextensionId
: The ID of the MetaMask extension
You can learn more about them in the Built-in Fixtures section.
To interact with MetaMask, create an instance of the MetaMask
class. For detailed information about the constructor and available methods, see the MetaMask 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.
Running Tests
To run your tests:
Currently, Synpress runs tests in headed mode by default (like playwright test --headed
).
To run in headless mode, set the HEADLESS
environment variable:
This default behavior will be changed in a future release to match Playwright’s standard behavior.
Synpress supports all Playwright features, including: