Synpress is e2e testing framework based around Cypress.io & playwright with included MetaMask support. Test your dapps with ease.
npm install @robertw07/synpress
!Synpress CI





> We're Hiring ๐ โ Think you have what it takes? We're looking for Software
> Engineer,
> find out more.
#

Synpress
is E2E testing framework
based on Cypress
and Playwright
with support for MetaMask.
#

Synpress makes sure to always use latest version of metamask and puts a lot of
effort to make sure that dapp tests are stable and trustful.
It also provides an easy way to use and access metamask straight from your e2e
tests with all features of cypress and playwright.
๐ฅ Synpress works out-of-the-box with other frameworks! There is no need to use
it directly. Check
usage examples for
more details.
โ ๏ธ This branch showcases the current stable release of Synpress which will receive only critical hotfixes. โ ๏ธ
Active development of the upcoming version of Synpress is happening on this branch.
The new release is a full rewrite of Synpress and will feature major breaking changes, and multitude of new features and improvements across the board such as:
- โญ Full TypeScript support
- โญ Multi-wallet support
- โญ Full parallelism support
- โญ Test runtime speed faster than any other Web3 alternative, and equal to native Web2 frameworks
Curious and want to learn more? ๐ค
Read this Twitter thread ๐งต and do not forget to check out the attached document there!
- [](#)
- [](#-1)
- Table of content
- ๐งโ๐คโ๐ง Community
- ๐ฅ๏ธ Install
- โ๏ธ Supported frameworks
- ๐ Supported wallets
- โ๏ธ Usage examples:
- ๐ Features
- ๐ท Example setup for eslint and tsconfig
- โก Important notes
- ๐ณ Using with Docker
- Requirements
- Some neat features
- How to run e2e tests for Synpress using Docker
- ๐โโ๏ธ CI tips \& tricks
- ๐งช Usage \& commands
- ๐ Environmental variables
- ๐ข Release process
- ๐ More resources
- Discord => for live support and direct
chat with devs.
- Twitter => for updates and announcements.
``bash`with pnpm
pnpm add --save-dev @synthetixio/synpresswith npm
npm install --save-dev @synthetixio/synpresswith yarn
yarn add -D @synthetixio/synpress
- Synpress
- Playwright (as a plugin)
- Cypress (as a plugin)
- MetaMask
- โญ Synpress examples
- Synpress e2e tests
---
For full Synpress commands and their examples,
check here.
To see in which direction Synpress is headed to, take a look at
planning board.
- Added support for metamask ๐ฆ
- Supports headless mode ๐ค (synpress run --headless).env
- Recommended for local development (but
not for CI yet as
it's new and experimental)
- Integrated with
Docker ๐ณ
- Recommended for
CI
- Includes VNC and noVNC
- Integrated video recording ๐ฅ (full screen)
- Exposes noVNC with ngrok (optional)
- Easy to debug ๐
- Improved error handling
- Supports cypress and
playwright debuggers
- noVNC allows for interactions through browser ๐
- Debug remote machines on CI with ngrok
- Blazingly-fast โก
- Extensible โ๏ธ (add own custom commands and plugins)
- Can be used in existing
Cypress setup
- Supports dotenv
- Loads all env vars from your file automatically (from project root
folder)
- Ability to use latest metamask or lock it's version to avoid unexpected
failures related to metamask updates
- Supports multi-lang of metamask, it doesn't depend on any labels
- Synpress is
fully tested
- Waits for XHR requests, navigations and animations automatically
- Ability to fail test run if there are any browser console errors found
- Types support for all additional custom commands
- The best possible options set up in place to avoid flakiness
- Etherscan API helpers in place which for ex. allows to compare your
transaction results with etherscan and check tx status
- Synthetix helpers in place which allows to interact with synthetix protocol
programmatically
- Supports codespaces
- Run your tests in docker
- Get your feedback remotely thanks to ngrok
- Use mpeg-4 preview plugin to watch videos from inside codespaces :) ...
Project structure:
`text`
project_dir
โโโ src
โโโ tests
โโโ e2e
โโโ .eslintrc.js
โโโ support.js
โโโ tsconfig.json
โโโ specs
โโโ example-spec.js
โโโ pages
โโโ example-page.js
1. Create .eslintrc.js inside your tests folder (/project_dir/tests/e2e):
`js
const path = require('path');
const synpressPath = path.join(
process.cwd(),
'/node_modules/@synthetixio/synpress',
);
module.exports = {
extends: ${synpressPath}/.eslintrc.js,`
};
2. Create support.js inside your tests folder (/project_dir/tests/e2e):
`js`
import '@synthetixio/synpress/support/index';
_^ hint: you can also use this file to extend synpress - add custom commands,
and more.._
3. Create tsconfig.json inside your tests folder (/project_dir/tests/e2e):
`json`
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../../node_modules",
"types": [
"cypress",
"@synthetixio/synpress/support",
"cypress-wait-until",
"@testing-library/cypress"
],
"outDir": "./output"
},
"include": ["*/.*"]
}
4. You're done! ๐
To change specific values in default config, you can use --config flag. Forsupport.js
example, to change path for file, you can usesynpress run --config "supportFile=__tests__/e2e/supportFile.js"
If you would like to use custom paths for your tests and configs, you should
mirror (full) default synpress config
and then modify it for your needs. Then you can direct synpress to use it with
--configFile flag.
For example: synpress run --configFile __tests__/e2e/customConfig.config.js
Synpress doesn't seem to communicate with metamask properly if
"chromeWebSecurity": false flag is set. More about it
here.
Thanks to
new headless mode in Chrome,
tests are now working in headless mode ๐ค (synpress run --headless). However,
I recommend to use it only for local development as this feature is new and
experimental and may cause issues on CI (UNIX). So please, stick to non-headless
mode on CI.
In the past, tests worked only in non-headless mode because extensions were not
supported in headless mode by
playwright and
Cypress.
As a workaround, we've provided Docker ๐ณ containers. They solved this issue and
it's an alternative.
You have to setup xvfb and window manager (like fluxbox or xfce4) to runDISPLAY
tests without issues on CI (together with env var). Take a look at
CI tips & tricks
for working examples.
There is a global
before()
which runs metamask setup before all tests:
- passes welcome page
- imports wallet
- changes network (defaults to goerli) or creates custom network and changes
to it (depending on your setup)
- switches back to Cypress window and starts testing
It requires environmental variable called SECRET_WORDS to be present in'word1 word2 word3 ..'
following format => (delimited with spaces) or privatePRIVATE_KEY
key in an environmental variable called .
To change default network (goerli), you can use NETWORK_NAME environmentalNETWORK_NAME=sepolia
variable, for example: .
Available choices are: mainnet, goerli, sepolia and localhost.
To create and switch to custom network at metamask setup phase, use these:
1. NETWORK_NAME => ex: synthetixRPC_URL
2. => ex: https://synthetix-node.ioCHAIN_ID
3. => ex: 123SYMBOL
4. => ex: SNXBLOCK_EXPLORER
5. (optional) => ex: https://synthetix-explorer.ioIS_TESTNET
6. (optional) => ex: false
Metamask version is hardcoded and frequently updated under supervision to avoid
a case when e2e tests break because of CSS classes changes in new version, so
all you need is to keep synpress updated in your project. However, you can still
override metamask with METAMASK_VERSION environmental variable, for example:METAMASK_VERSION=10.21.0 or METAMASK_VERSION=latest.
If you don't want to use environmental variables, you can modify
setupMetamask()
to following:
setupMetamask(secretWordsOrPrivateKey, network, password), for example:setupMetamask('word1 word2 word3 ..', 'mainnet', 'password') (delimited with
spaces).
You can also add and switch to custom network by passing an object instead ofstring inside setupMetamask(secretWordsOrPrivateKey, network, password)network
function for parameter.
If you want to use Etherscan API helpers, you will have to provide Etherscan API
key using ETHERSCAN_KEY environmental variable.
To fail a test if there are any browser console errors, set FAIL_ON_ERROR to1 or true.
Automatic waiting for XHR requests to finish before tests start can be turned on
with CYPRESS_RESOURCES_WAIT environmental variable, set it to 1 or true.
If you want to skip metamask extension installation or metamask setup, you can
use SKIP_METAMASK_INSTALL and SKIP_METAMASK_SETUP separately. Both variables1
accept or true.
Synpress is blazingly-fast โก by default! If you want to change that, you can
use STABLE_MODE=true (which will introduce delays only between main actions,STABLE_MODE=
300ms by default) / or SLOW_MODE=true (which willSLOW_MODE=
introduce delay between every action, 50ms by default) / .
DEBUG=synpress:* is very useful while debugging your tests. It enables
following features:
- improved logging
- Cypress debugger
- Playwright debugger
- slow down tests
You may encounter 403 errors (on shared IPs & CI) related to rate limiting while
fetching metamask releases from GitHub REST API. This should never happen at
all, but it's good to mention. To prevent it from happening, you can create new
private access token on GitHub (without any additional access) and specify
GH_USERNAME & GH_PAT environmental variables.
Docker is awesome for CI. Give it a try.
- based on docker-e2e โค
- full screen video recording ๐ฅ (together with metamask extension)
- VNC & noVNC support ๐ฅ๏ธ (very easy to debug with browser)
- local: http://localhost:8080/vnc.html?autoconnect=true
- ngrok ๐ integration (exposes noVNC for everyone)
- remote: https://
url)
1. git clone git@github.com:Synthetixio/synpress.gitcd synpress
2. .env
3. (optional) Fill env vars inside filedocker-compose --profile synpress --profile foundry up --build --exit-code-from synpress
4. (with foundry; preferred)
./start-tests.sh
or docker-compose up --profile synpress --build --exit-code-from synpress
- (without foundry)
docker-compose --profile synpress --profile foundry --profile ngrok up --build --exit-code-from synpress
5. (with foundry and ngrok)
All examples of setup are present in this repository. Just take a look around.
- Check out many different examples for GitHub Actions
in this repository:
- e2e_headful.yml
=> runs on ubuntu-latest.ubuntu-latest
- e2e_debug.yml
=> runs on , has configured VNC, noVNC and ngrok for easyubuntu-latest
debugging.
- e2e_docker.yml
=> runs on with docker compose stack.ubuntu-latest
- e2e_cypress-action.yml
=> runs on , using official
cypress-io/github-action.
- You can find examples for GitLab CI =>
here.
- Use docker-e2e
- Synpress is tested and should work on all resolutions, starting from 800x600
- synpress run to run testssynpress open
- to open Cypress UI (may be bugged in some cases because itsynpress run
doesn't clear metamask state before each e2e test, please use )
Command line interface (synpress help):
`text
Usage: synpress run [options]
launch tests
Options:
-b, --browser
-c, --config
-cf, --configFile
-e, --env
-s, --spec
-ne, --noExit keep runner open after tests finish
-pr, --project
-q, --quiet only test runner output in console
-r, --reporter
-ro, --reporterOptions
-r, --record [dashboard] record video of tests running after setting up your project to record
-k, --key
-p, --parallel [dashboard] run recorded specs in parallel across multiple machines
-g, --group [name] [dashboard] group recorded tests together under a single run
-t, --tag
-h, --help display help for command
`
`text
Usage: synpress open [options]
launch test runner UI
Options:
-cf, --configFile
-h, --help display help for command
`
If your MetaMask is stuck on the loading screen, check what's happening under the hood in the console. You can find vital information about why it's stuck on this step.
#### โญ Sentry.io HTTP error 499 (Request has been forbidden by antivirus)
- Kaspersky antivirus sometimes blocks encrypted requests to Sentry.io. You can disable
this feature in Kaspersky advanced settings by toggling on "Do not scan encrypted connections".
| Variable | Description |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| SECRET_WORDS | Space separated words for the test wallet recovery phrase (mnemonic; 12 words) |PRIVATE_KEY
| | Test wallet private key |NETWORK_NAME
| | Network name (eg NETWORK_NAME=Optimism) |RPC_URL
| | Network RPC (egRPC_URL=https://mainnet.optimism.io) |CHAIN_ID
| | Network ID (egCHAIN_ID=10) |SYMBOL
| | Native chain token ticker (eg SYMBOL=OP) |IS_TESTNET
| | boolean indicates that the added network is testnet |BLOCK_EXPLORER
| | Blockchain explorer (eg BLOCK_EXPLORER=https://optimistic.etherscan.io/) |SYNDEBUG
| | Set debugging mode to be on |STABLE_MODE
| | Introduce delay between main actions, 300ms by default (eg STABLE_MODE=300ms, STABLE_MODE=true) |SLOW_MODE
| | Introduce delay between every action, 50ms by default (eg SLOW_MODE=true, SLOW_MODE=200ms) |METAMASK_VERSION
| | Metamask version to be installed |SKIP_METAMASK_INSTALL
| | Will skip MetaMask installation |SKIP_METAMASK_SETUP
| | Will skip MetaMask initial setup |GH_USERNAME
| | GitHub username (used to avoid rate-limit issues while downloading Metamask) |GH_PAT
| | GitHub personal access token (used to avoid rate-limit issue while downloading metamask) |ETHERSCAN_KEY
| | Etherscan key (used only for etherscan-related commands) |FAIL_ON_ERROR
| | Fail a test if there are any browser console errors |CYPRESS_GROUP
| | Group tests |CI
| | Boolean value indicates that tests are running from CI/CD pipeline |
1. Create PR from dev branch to master branch-beta
2. Merge it (new version is automatically released)patch|minor|major
3. Run GitHub Action workflow named
Release CI
with depending on your needs to promote your build.
Alternatively, instead of running GitHub Action for release, you can move on
with manual release process:
1. Switch to master branch and pull latest changespnpm release:patch/minor/major
2. Run commanddev
3. Keep branch up to date with master`
Above actions will lead to:
- New npm node module release
- New GitHub packages node module release
- New GitHub release (tagged) created with changelog from commit messages
- End-to-end testing using Synpress
- Synpress - web3-enabled e2e testing tool
- How to set up Synpress for Web3 dApp Frontend Test Automation with MetaMask
- Extending Synpress with additional MetaMask commands
- Test e2e login to dApp with Metamask with Synpress