Package Exports
- koweb3test
- koweb3test/launcher.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (koweb3test) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Fork of Synpress with some added cypress features such as xpath , file upload functions
[koweb3test]is a wrapper around Cypress.io with metamask support thanks to puppeteer.
koweb3test makes sure to always use latest version of metamask before tests are ran.
It also provides an easy way to use metamask straight from your e2e tests.
Features:
- metamask support
- ability to use latest metamask or lock it's version to avoid unexpected failures related to metamask update
- supports multi-lang of metamask, it doesn't depend on any labels
- automatically waits for all XHR requests to be finished before tests are run
- ability to fail e2e tests if there are any browser console error found during test run
- 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
๐ท Example setup for eslint and tsconfig
Project structure:
project_dir
โโโ src
โโโ tests
โโโ e2e
โโโ .eslintrc.js
โโโ tsconfig.json
โโโ specs
โโโ example-spec.js
โโโ pages
โโโ example-page.js
- Create
.eslintrc.js
inside your tests folder (/project_dir/tests/e2e
):
const path = require('path');
const koweb3testPath = path.join(process.cwd(), '/node_modules/@synthetixio/koweb3test');
module.exports = {
extends: `${koweb3testPath}/.eslintrc.js`,
};
- Create
tsconfig.json
inside your tests folder (/project_dir/tests/e2e
):
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../../node_modules",
"types": ["cypress", "@types/puppeteer-core", "@synthetixio/koweb3test/support", "cypress-wait-until", "@testing-library/cypress"],
"outDir": "./output"
},
"include": ["**/*.*"]
}
- You're done! ๐
If you would like to use custom paths for your tests and configs, feel free to mirror default koweb3test config and modify it for your needs. Then you can direct koweb3test to use it with --configFile
flag.
For example: koweb3test run --configFile __tests__/e2e/customConfig.json
โก Important
koweb3test doesn't seem to communicate with metamask properly if "chromeWebSecurity": false
flag is set.
Tests work only in headed mode because extensions are not supported in headless mode in puppeteer and Cypress. It's intended to be used in conjunction with xvfb
on CI.
There is a global [before()
]which runs metamask setup before all tests:
- passes welcome page
- imports wallet
- changes network (defaults to
kovan
) 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 following format => 'word1, word2, etc..'
or private key in an environmental variable called PRIVATE_KEY
.
To change default network (kovan
), you can use NETWORK_NAME
environmental variable, for example: NETWORK_NAME=rinkeby
.
Available choices are: mainnet
, ropsten
, kovan
, rinkeby
, goerli
and localhost
.
To create and switch to custom network at metamask setup phase, use these:
NETWORK_NAME
=> ex:examplenetwork
RPC_URL
=> ex:https://abc-node.io
CHAIN_ID
=> ex:123
SYMBOL
(optional) => ex:TEST
BLOCK_EXPLORER
(optional) => ex:https://test-explorer.io
IS_TESTNET
(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 koweb3test updated in your project. However, you can still override metamask with METAMASK_VERSION
environmental variable, for example: METAMASK_VERSION=9.3.0
or METAMASK_VERSION=latest
.
If you don't want to use environmental variables, you can modify [setupMetamask()
]
setupMetamask(secretWordsOrPrivateKey, network, password)
, for example: setupMetamask('word1, word2, etc..', 'mainnet', 'password')
.
You can also add and switch to custom network by passing an object
instead of string
inside setupMetamask(secretWordsOrPrivateKey, network, password)
function for network
parameter.
If you want to use Etherscan API helpers, you will have to provide Etherscan API key using ETHERSCAN_KEY
enironmental variable.
To fail a test if there are any browser console errors, set FAIL_ON_ERROR
to 1
or true
.
Automatic waiting for XHR requests to finish before tests start can be turned off with CYPRESS_SKIP_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 variables accept 1
or true
.
๐งช Usage
koweb3test run
to run testskoweb3test open
to open Cypress UI (may be bugged in some cases because it doesn't clear metamask state before each e2e test, please usekoweb3test run
)
Command line interface (koweb3test help
):
Usage: koweb3test run [options]
launch tests
Options:
-b, --browser <name> run on specified browser (default: "chrome")
-c, --config <config> set configuration values, separate multiple values with a comma
-cf, --configFile <path> specify a path to a JSON file where configuration values are set
-e, --env <env=val> set environment variables, separate multiple values with comma
-s, --spec <path or glob> run only provided spec files
-ne, --noExit keep runner open after tests finish
-pr, --project <path> run with specific project path
-q, --quiet only test runner output in console
-r, --reporter <reporter> specify mocha reporter
-ro, --reporterOptions <options> specify mocha reporter options, separate multiple values with comma
-r, --record [dashboard] record video of tests running after setting up your project to record
-k, --key <key> [dashboard] set record 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 <name> [dashboard] add tags to dashboard for test run
-h, --help display help for command
Usage: koweb3test open [options]
launch test runner UI
Options:
-cf, --configFile <path> specify a path to a JSON file where configuration values are set
-h, --help display help for command