Giter Site home page Giter Site logo

synthetixio / synpress Goto Github PK

View Code? Open in Web Editor NEW
532.0 14.0 164.0 32.45 MB

Synpress is e2e testing framework based on Cypress.io and playwright with support for metamask.

Home Page: https://synpress.io

License: MIT License

JavaScript 99.47% Shell 0.31% Dockerfile 0.21%
cypress metamask testing blockchain ethereum e2e playwright docker

synpress's Introduction

npm version Synpress CI CodeQL Release CI synpress Discord Twitter Follow

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.

Sponsored & used by:

Synthetix Optimism

Power users:

Phantom Ethereum Name Service (ENS) Kwenta
Panther Protocol Guild Aragon Delvtech
Offchain Labs Snapshot Labs Hedera

Synpress Demo

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.

โ™จ๏ธ New release

โš ๏ธ 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!

Table of content

๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ Community

  • Discord => for live support and direct chat with devs.
  • Twitter => for updates and announcements.

๐Ÿ–ฅ๏ธ Install

# with pnpm
pnpm add --save-dev @synthetixio/synpress
# with npm
npm install --save-dev @synthetixio/synpress
# with yarn
yarn add -D @synthetixio/synpress

โš™๏ธ Supported frameworks

๐Ÿ‘ Supported wallets

โœ๏ธ Usage examples:


For full Synpress commands and their examples, check here.

To see in which direction Synpress is headed to, take a look at planning board.

๐ŸŒŸ Features

  • Added support for metamask ๐ŸฆŠ
  • Supports headless mode ๐Ÿค– (synpress run --headless)
    • 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 .env 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 :) ...

๐Ÿ‘ท Example setup for eslint and tsconfig

Project structure:

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):
const path = require('path');
const synpressPath = path.join(
  process.cwd(),
  '/node_modules/@synthetixio/synpress',
);

module.exports = {
  extends: `${synpressPath}/.eslintrc.js`,
};
  1. Create support.js inside your tests folder (/project_dir/tests/e2e):
import '@synthetixio/synpress/support/index';

^ hint: you can also use this file to extend synpress - add custom commands, and more..

  1. Create tsconfig.json inside your tests folder (/project_dir/tests/e2e):
{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": "../../node_modules",
    "types": [
      "cypress",
      "@synthetixio/synpress/support",
      "cypress-wait-until",
      "@testing-library/cypress"
    ],
    "outDir": "./output"
  },
  "include": ["**/*.*"]
}
  1. You're done! ๐ŸŽ‰

To change specific values in default config, you can use --config flag. For example, to change path for support.js file, you can use synpress 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

โšก Important notes

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 run tests without issues on CI (together with DISPLAY 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 following format => 'word1 word2 word3 ..' (delimited with spaces) or private key in an environmental variable called PRIVATE_KEY.

To change default network (goerli), you can use NETWORK_NAME environmental variable, for example: NETWORK_NAME=sepolia.

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: synthetix
  2. RPC_URL => ex: https://synthetix-node.io
  3. CHAIN_ID => ex: 123
  4. SYMBOL => ex: SNX
  5. BLOCK_EXPLORER (optional) => ex: https://synthetix-explorer.io
  6. 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 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 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 environmental 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 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 variables accept 1 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, 300ms by default) / STABLE_MODE=<value> or SLOW_MODE=true (which will introduce delay between every action, 50ms by default) / SLOW_MODE=<value>.

DEBUG=synpress:* is very useful while debugging your tests. It enables following features:

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.

๐Ÿณ Using with Docker

Docker is awesome for CI. Give it a try.

Requirements

Some neat features

  • based on docker-e2e โค
  • full screen video recording ๐ŸŽฅ (together with metamask extension)
  • VNC & noVNC support ๐Ÿ–ฅ๏ธ (very easy to debug with browser)
  • ngrok ๐Ÿ”Œ integration (exposes noVNC for everyone)
    • remote: https://.ngrok.io/vnc.html?autoconnect=true (check logs for url)

How to run e2e tests for Synpress using Docker

  1. git clone [email protected]:Synthetixio/synpress.git
  2. cd synpress
  3. (optional) Fill env vars inside .env file
  4. (with foundry; preferred) docker-compose --profile synpress --profile foundry up --build --exit-code-from synpress or ./start-tests.sh
    • (without foundry) docker-compose up --profile synpress --build --exit-code-from synpress
  5. (with foundry and ngrok) docker-compose --profile synpress --profile foundry --profile ngrok up --build --exit-code-from synpress

All examples of setup are present in this repository. Just take a look around.

๐Ÿ’โ€โ™‚๏ธ CI tips & tricks

๐Ÿงช Usage & commands

  • synpress run to run tests
  • synpress open to open Cypress UI (may be bugged in some cases because it doesn't clear metamask state before each e2e test, please use synpress run)

Command line interface (synpress help):

Usage: synpress 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 *.js 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: synpress open [options]

launch test runner UI

Options:
  -cf, --configFile <path>  specify a path to *.js file where configuration values are set
  -h, --help                display help for command

๐Ÿ‘จโ€โš•๏ธ Known problems with MetaMask

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".

๐Ÿ“ƒ Environmental variables

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

๐Ÿšข Release process

  1. Create PR from dev branch to master branch
  2. Merge it (new -beta version is automatically released)
  3. Run GitHub Action workflow named Release CI with patch|minor|major 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 changes
  2. Run pnpm release:patch/minor/major command
  3. Keep dev 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

๐Ÿ“ More resources

synpress's People

Contributors

afitzy98 avatar anthanh avatar brendankirby avatar danivm avatar dependabot[bot] avatar dewanshparashar avatar drptbl avatar duckception avatar einaralex avatar eulerbeat5 avatar fionnachan avatar gitter-badger avatar maxhoheiser avatar nataliexselina avatar neuodev avatar niemam29 avatar noahlitvin avatar piotrfrankowski avatar r3kt-eth avatar rafal2228 avatar roninjin10 avatar shawnwang0715 avatar stylishtriangles avatar vigneshka avatar yakovl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

synpress's Issues

Cannot read property 'waitForTimeout' of undefined

I use command synpress open after this command i can't use function cy.confirmMetamaskWelcomePage() in '@synthetixio/support/index.js' and on cypress window show err = "Cannot read property 'waitForTimeout' of undefined"
how i should handle them all.

Thank you

Metamask Extension Not Opening in Separate Tab

After running export SECRET_WORDS=some-secret-words; export RPC_URL=https:\/\/kovan.infura.io\/v3\/9aa3d95b3bc440fa88ea12eaa4456161; export CHAIN_ID=42; npx synpress run -b firefox

The resulting cypress instance not have MetaMask setup open in a separate tab, I am not sure what caused this to happen as it was setting up properly previously.

Can't connect to dApp after switching account.

When switching accounts in the MetaMask notification window, it would show a prompt to let you connect the next account to your dApp. However synpress switches accounts in a new tab of MetaMask (expanded view). In this case, the prompt won't show, so the new account won't be able to interact with the dApp...

I guess one workaround is that make synpress 'select all' accounts when it makes MetaMask connect to the dApp for the first time.

setupMetamask Errors with Electron

EDIT: I might just be dumb, this probably shouldn't work with Electron, right?

Getting the following issue only when running Electron.

The first issue I was getting was with the remote debugger

CypressError: `cy.task('setupMetamask')` failed with the following error:

> request to http://localhost:9222/json/version failed, reason: connect ECONNREFUSED 127.0.0.1:9222

which I fixed by exporting ELECTRON_EXTRA_LAUNCH_ARGS=--remote-debugging-port=9222. I'd suggest some way to handle this internally, or at least a line of documentation.

CypressError: `cy.task('setupMetamask')` failed with the following error:

> Cannot read property 'waitForTimeout' of undefined

It seems like await metamask.initialSetup({ secretWords, network, password }); from the plugin is being called before puppeteer has been been properly set up.

Note that I've configured metamask to use a custom network.

Stuck on metamask window when using a custom network

Hi thanks for this really cool tool. I have a couple of issues here. Main issue is that when I enter a custom network, the screen stays stuck on metamask screen and times out. It works fine when I use one of the pre installed networks.

I also wanted to ask if there was an easy way to add more configuration without changing it in the node modules. For example, more custom commands or events (ex. on, uncaught:error)

confirm / provide Request encryption public key

Hi, I want to confirm the request to provide a encryption public key with synpress, but I could not find it as a custom command. Is there a way to confirm arbitrary requests to metamask independent of the type via puppeteer?

cypress thinks that `cy.task('setupMetamask')` is not finished

I cannot run my tests cuz cypress thinks that cy.task('setupMetamask') is not finished
Metamask setup goes smooth, then first test cannot start because cypress hangs on before all hook. Extending defaultCommandTimeout does not help

On the first run (just after install synpress) i got Cannot read property 'waitForTimeout' of undefined then error disappeared but above problem happen

image
image
image

1) Connect-view
       Connecting
         "before all" hook for "should login to app":
     CypressError: `cy.task('setupMetamask')` failed with the following error:

> waiting for function failed: timeout 30000ms exceeded

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": "../../node_modules",
    "types": [
      "cypress",
      "@types/puppeteer-core",
      "@synthetixio/synpress/support",
      "cypress-wait-until",
      "@testing-library/cypress"
    ],
    "outDir": "./output",
    "lib": ["ESNext", "dom"]
  },
  "include": ["**/*.*"]
}

.env

PRIVATE_KEY=...

NETWORK_NAME=BSC-Testnet
RPC_URL=https://data-seed-prebsc-1-s1.binance.org:8545/
CHAIN_ID=97
SYMBOL=BNB
BLOCK_EXPLORER=https://testnet.bscscan.com/
IS_TESTNET=true

spec

import * as connectViewAction from '../../actions/connect-view-actions';

describe('Connect-view', () => {
  context('Connecting', () => {
    it('should login to app', () => {
      connectViewAction.connectViaMetamask();
    });
  });
});

...

export const connectViaMetamask = () => {
  navigationActions.goToConnectView();

  connectViewPage.getConnectViaMetamaskButton().click();

  cy.acceptMetamaskAccess().then(connected => {
    expect(connected).to.be.true;
  });
};

confirmMetamaskPermissionToSpend Error

task.(confirmMetamaskPermissionToSpend)
CypressError
cy.task('confirmMetamaskPermissionToSpend') failed with the following error:

Cannot read property 'waitForTimeout' of undefined

The call to approve permission for spend of coins works - invokes the metamask popup

Fails on: cy.confirmMetamaskPermissionToSpend();

confirmMetamaskTransaction function fails with the default metamask version 9.7.1

Thanks for the great work on Synpress, this library looks awesome. Anyway I am struggling with something when I try to confirm transactions.

Steps to reproduce:
Leave env variable for metamask version blank (use the hardcoded version 9.7.1)
Execute: synpress run
Metamask is being initialized
The chosen address is visited
The user wallet is connected to the dApp
Button leading to transaction which needs confirmation from metamask is pressed.

Once needed to confirm metamask transaction, it is failed(screenshot attached)

metamask

Note:
Debugged the library and found where the confirmation is failing

cy.confirmMetamaskTransaction is calling -> confirmTransaction in ./commands/metamask.js
which is calling:
await puppeteer.waitClearAndType( newGasFee, confirmPageElements.gasFeeInput, notificationPage, ); - all the params passed to waitClearAndType defined.

The function waitClearAndType is failing on the step:
await input.click({ clickCount: 3 }); Where 'input' is defined.

I tried to replace waitClearAndType with waitAndType when called from confirmTransaction and the transaction is passed successfully ( but the gas fee paid for the transaction is not right of course)
Other workaround I tried is to skip the calling of waitClearAndType it is working as well, but there is possibility for the transaction not to be mined if the gas fee increased from the moment we triggered the transaction.

Also if some of the latest versions of Metamask is used(tried with 10.2.2), confirmMetamaskTransaction is failing as well as in the last versions of Metamask, the confirmation page has no input field for the gas fee at all and it seems that the gas fee is recalculated by Metamask automatically. For these versions of metamask we could skip the steps for manually getting and setting the gas fee.

Failing to complete setupMetamask.

I have the following simple test. I've also set it up almost exactly as in the instructions. However, synpress is failing with the following error:

cy.task('setupMetamask') failed with the following error:
> waiting for function failed: timeout 30000ms exceeded
Because this error occurred during a before all hook we are skipping the remaining tests in the current suite:

Any idea what's going on?

describe('mint on the app.', () => {
    before(() => {
      cy.setupMetamask(
        'test test test test test test test test test test test junk',
        'localhost',
        'Tester@1234',
      ).then(setupFinished => {
        expect(setupFinished).to.be.true;
      });
      cy.visit('/')
    })

    it('visits the homepage and logs into web3sso.', () => {      
      cy.visit('/')
      cy.wait(2000)
      cy.get('#web3SSO').contains("Connect").click()
      cy.wait(2000) // wait 2s.
      cy.get('.web3modal-provider-name div').contains("MetaMask").click()
      cy.wait(2000) // wait 2s.
      cy.get('#headlessui-menu-button-3').should('have.text', '0xf39F');
    })
})

Use Cypress plugins with synpress?

Is it possible to use Cypress plugins?
I defined these in cypress.json:

{
  "supportFile": "cypress/support/index.js",
  "pluginsFile": "cypress/plugins/index.js",
}

But the plugins only seem to be loaded when using synpress open not with synpress run.
I would like to use cypress-file-upload and custom commands.

I also can't see any plugin-related folders is the example project structure in the README.

Partial issues with metamask while running tests with "chromeWebSecurity: false"

It seems that metamask doesn't work well with Synpress if it's run with "chromeWebSecurity": false flag.
There seems to be some issues with connection between metamask and browser in this case.

In case of 1inch, I wasn't able to connect my wallet:
Screenshot 2020-12-04 at 21 16 34

In case of kwenta, I was able to connect my wallet, but dapp couldn't read any balances from it.
Screenshot 2020-12-04 at 16 59 11

Everything works fine with "chromeWebSecurity": true.
https://docs.cypress.io/guides/guides/web-security.html

Couldn't find anything helpful in this topic, only issues without answers, like this one:
MetaMask/metamask-extension#6817

Why am i socket hang up or ETIMEDOUT?

i havn't change anything, and the test file are almost empty, but always socket hang up or ETIMEDOUT?

2021-08-27_17-40
2021-08-28_09-39
2021-08-28_09-39_1
2021-08-28_09-39_2
2021-08-28_10-17

please help me, thanks, i don't know how to let it work

Unexpected Token Export in Angular App

Hi - I'm working on getting synpress setup within an Angular app and getting this error:

export const welcomePageElements = {
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1060:16)
    at Module._compile (internal/modules/cjs/loader.js:1108:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12694)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/Will/Desktop/Programming/aws-definer-app-v2/node_modules/@synthetixio/synpress/commands/metamask.js:10:5)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12694)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/Will/Desktop/Programming/aws-definer-app-v2/node_modules/@synthetixio/synpress/plugins/index.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12694)

If I edit the file to use module.exports instead of export const then I can get things working. Any tips on how I can setup my environment to work without going into synpress and editing the files? Thanks!

Apply for Gitcoin grant

Recently came across this project when trying to see how best to test Dapps. I think it will be invaluable for the community, maybe to help support the development of it you might consider applying for a Gitcoin grant

I can't make it work on Gitlab CI

Hi guys,

Have somebody ever make synpress work with some CI? I'm trying to make it work with Gitlab CI, but it doesn't work.

Thanks a lot!

Best regards,

Error at confirmMetamaskTrancsaction

I've tried using the module for testing, the processes such as set up wallet is ok. However, I've found the error on confirm a transaction, here is the prompt shown in Cypress.

  at <unknown> (__puppeteer_evaluation_script__:1:64)
  at <unknown> (__puppeteer_evaluation_script__:1:64)
    at <unknown> (http://localhost:3000/__cypress/runner/cypress_runner.js:142397:20)
From previous event:
    at Context.task (http://localhost:3000/__cypress/runner/cypress_runner.js:142379:16)
From Your Spec Code:

From Node.js Internals:
    Error: Evaluation failed: ReferenceError: _this is not defined
      at <unknown> (__puppeteer_evaluation_script__:1:64)

I've tried searching for workaround in Puppeteer but there is no clue in this case.

Can't add network in docker container

Sorry, I can't find a way to re-open the issue in #215, so I create a new one.

When I try to add a network in docker container, it always gets stuck in here:

await puppeteer.waitForText(
mainPageElements.networkSwitcher.networkName,
network.networkName,

Here's my docker-compose.yml:

services:
  synpress:
    image: synthetixio/docker-e2e:14.17-debian
    volumes:
      - './synpress:/home/app'
      - './synpress/node_modules:/home/node/app/node_modules'
    entrypoint: ["tail", "-f", "/dev/null"]
    environment:
      - SECRET_WORDS="test test test test test test test test test test test junk"
      - NETWORK_NAME="Smart Chain"
      - RPC_URL="https://bsc-dataseed.binance.org/"
      - CHAIN_ID="56"
      - SYMBOL="BNB"
      - BLOCK_EXPLORER="https://bscscan.com"

After starting the docker container, I run these commands:

npm i @synthetixio/synpress
npx synpress run --browser chrome --configFile 'tests/e2e/synpress.json'

My synpress.json has nothing special. I only changed the baseUrl

Then I always get

     CypressError: `cy.screenshot()` timed out waiting `30000ms` to complete.

Because this error occurred during a `before all` hook we are skipping all of the remaining tests.

Although you have test retries enabled, we do not retry tests when `before all` or `after all` hooks fail

Could you check whether adding network works in docker? Thanks!

npm install @synthetixio/synpress

Fails as dependency tree cant resolve.
It seems there is an issue with webpack.
I am trying to adequately understand the issue to try and suggest a fix, but I am struggling to learn fast enough :).

npm i @synthetixio/synpress failed

npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected].
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'synthetix'
npm ERR! notarget

npm ERR! A complete log of this run can be found in:

changeMetamaskNetwork is not working

Hi again,

The changeMetamaskNetwork is not working currently I tried to call it with and without await but it doesn't fix the issue.

My output

 CypressError: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

  > `cy.task()`

The cy command you invoked inside the promise was:

  > `cy.changeMetamaskNetwork()`

Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.
      at $Cy.cy.<computed> [as changeMetamaskNetwork] (http://localhost:3000/__cypress/runner/cypress_runner.js:157795:23)

Import by private key is not working

Hey,

So everything seems to work fine on my side except regarding the import by private key feature.

When I declare my env variable with SECRET_WORDS everything works fine but when I try to use PRIVATE_KEY instead the setup goes to seed phrase page of metamask anyway and gets stuck here since my SECRET_WORDS env variable isn't set.

I tried running by setting both SECRET_WORDS and PRIVATE_KEY but it doesn't seem to import my account and sticks with the first address...
I also tried to call cy.importMetamaskAccount but the function is not recognized and here is the output

"before all" hook for "Connects with metamask wallet":
     TypeError: cy.importMetamaskAccount is not a function

Cannot read property 'bringToFront' of undefined

Hi

thanks for this amazing repo

I am having an issue with the initial setupMetamask phase
after the secret pass, phrase || password step has finished

Screen Shot 2021-08-13 at 13 01 56

might have missed something
should I configure "bringToFront" anywhere?

Thanks

Cannot run in docker with Xvfb installed

I found some behaviors are weird and make this can't run in docker.

  1. In this line:

    if (page.url().includes('integration')) {

    It detects whether the URL contains integration, however, Cypress seems doesn't have __/#/tests/integration suffix when running in docker, and this makes this detection failed.

  2. I don't know why but I get stuck in this line when running with docker:

    await puppeteer.waitForText(
    mainPageElements.networkSwitcher.networkName,
    network.networkName,

    It always shows timeout, and because I don't know how to see the video playback of the extension page, I don't know what happened there.

Thanks!

Running `synpress open` causes command to be run in loop

After running export NETWORK_NAME=rinkeby; export SECRET_WORDS=shuffle\ stay\ hair\ student\ wagon\ senior\ problem\ drama\ parrot\ creek\ enact\ pluck; npx synpress open

A command is executed in a loop and causes the cypress window to not open: npm exec synpress run -b firefox
image

Could possibly be coming from some cached value but not sure what would have caused this behavior in the first place.

Standalone version that doesn't ship Cypress and can be integrated into any setup.

Thanks for the good work with this wrapper. I was trying to use it and ran into some issues:

  • How can we extend our cypress setup by adding custom commands and other trivial things if the library is abstracting away the cypress commands and plugins file?
  • How can we use it in a typescript project with tests written in typescript?
  • Is there any better way to set up everything (especially the part of the eslint.js file)?
    Thanks in advance for your help!!!

Vue support

I see a lot of react in the dependencies, will this work with Vue.js?

CypressError: `cy.task('setupMetamask')` failed

Hey, I keep getting the following error even after doing the whole setup as described in synpress readme:

  1) Connect metamask wallet
       "before all" hook for "visits page":
     CypressError: `cy.task('setupMetamask')` failed with the following error:

> Cannot read properties of undefined (reading 'waitForTimeout')

https://on.cypress.io/api/task

Because this error occurred during a `before all` hook we are skipping all of the remaining tests.
      at http://localhost:3000/__cypress/runner/cypress_runner.js:161147:78
      at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:13196:23)
      at Promise._settlePromiseFromHandler (http://localhost:3000/__cypress/runner/cypress_runner.js:11131:31)
      at Promise._settlePromise (http://localhost:3000/__cypress/runner/cypress_runner.js:11188:18)
      at Promise._settlePromise0 (http://localhost:3000/__cypress/runner/cypress_runner.js:11233:10)
      at Promise._settlePromises (http://localhost:3000/__cypress/runner/cypress_runner.js:11309:18)
      at _drainQueueStep (http://localhost:3000/__cypress/runner/cypress_runner.js:7903:12)
      at _drainQueue (http://localhost:3000/__cypress/runner/cypress_runner.js:7896:9)
      at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:7912:5)
      at Async.drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:7782:14)
  From Your Spec Code:
      at Context.eval (http://localhost:3000/__cypress/tests?p=node_modules\@synthetixio\synpress\support\index.js:1036:15)

  From Node.js Internals:
    TypeError: Cannot read properties of undefined (reading 'waitForTimeout')
        at Object.initialSetup (C:\..\..\node_modules\@synthetixio\synpress\commands\metamask.js:558:37)
    at runMicrotasks (<anonymous>)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at setupMetamask (C:\..\..\node_modules\@synthetixio\synpress\plugins\index.js:211:7)

I run this code on package.json: "test:e2e": "start-server-and-test 'npm start' http-get://localhost:3000 'env-cmd -f .env synpress run'"

Here is my spec file:

describe("Connect metamask wallet", () => {
    it('visits page', () => {
        cy.visit('/')
    })
})

I don't know if this is the issue but I am using react functional components instead of nextjs and no typescript.
Please help.

Broken Selector for confirmMetamaskSignatureRequest();

Discussed in https://github.com/Synthetixio/synpress/discussions/324

Originally posted by saur-bh February 7, 2022
After investigation found that selector needs to be corrected in
@synthetixio/synpress/pages/metamask/notification-page.js as
{code}
const confirmSignatureRequestButton = ${notificationPage} .signature-request-footer :last-child;
const rejectSignatureRequestButton = ${notificationPage} .signature-request-footer :first-child;
{code}

which is
{code}
const confirmSignatureRequestButton = ${notificationPage} .request-signature__footer__sign-button;
const rejectSignatureRequestButton = ${notificationPage} .request-signature__footer__cancel-button;
{code}

Metamask setup blocks on seed phrase

Hey,

So I was just trying to launch a simple test with synpress run, the metamask extension opened in the test controlled browser but it just blocks on the wallet seed page. Synpress isn't typing my seed and I don't know why...

I checked my metamask version it's the latest 10.2.2 (so the latest).
Before running synpress run I call a bash script that sets my environment variables.

The script line in my package.json
"test:cli": "./.secret.sh && synpress run",

Below is my .secret.sh file that runs before tests and exports my env variables (obviously SECRET_WORDS and PRIVATE_KEY values have been changed here)

export SECRET_WORDS="word word..."
export PRIVATE_KEY=abcde1234
export NETWORK=localhost // by the way is it a problem if my metamask network is called hardhat 8545?
export RPC_URL=http://127.0.0.1:8545/
export CHAIN_ID=31337

// Just a simple check to be sure my env variables where set
echo $SECRET_WORDS
echo $PRIVATE_KEY
echo $NETWORK
echo $RPC_URL
echo $CHAIN_ID

Here is the output

====================================================================================================

  (Run Starting)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Cypress:    8.3.0                                                                              โ”‚
  โ”‚ Browser:    Chrome 94                                                                          โ”‚
  โ”‚ Specs:      1 found (connection-spec.js)                                                       โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
                                                                                                    
  Running:  connection-spec.js                                                              (1 of 1)


  1) "before all" hook for "An uncaught error was detected outside of a test"

  0 passing (34s)
  1 failing

  1) "before all" hook for "An uncaught error was detected outside of a test":
     CypressError: `cy.screenshot()` timed out waiting `30000ms` to complete.

Because this error occurred during a `before all` hook we are skipping all of the remaining tests.
      at http://localhost:3000/__cypress/runner/cypress_runner.js:145415:22
      at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:13212:23)
      at http://localhost:3000/__cypress/runner/cypress_runner.js:8334:41
      at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:13212:23)
      at Promise._settlePromiseFromHandler (http://localhost:3000/__cypress/runner/cypress_runner.js:11147:31)
      at Promise._settlePromise (http://localhost:3000/__cypress/runner/cypress_runner.js:11204:18)
      at Promise._settlePromise0 (http://localhost:3000/__cypress/runner/cypress_runner.js:11249:10)
      at Promise._settlePromises (http://localhost:3000/__cypress/runner/cypress_runner.js:11325:18)
      at _drainQueueStep (http://localhost:3000/__cypress/runner/cypress_runner.js:7919:12)
      at _drainQueue (http://localhost:3000/__cypress/runner/cypress_runner.js:7912:9)
      at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:7928:5)
      at Async.drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:7798:14)



Warning: We failed processing this video.

This error will not alter the exit code.

TimeoutError: operation timed out
    at afterTimeout (/Users/vitch/Library/Caches/Cypress/8.3.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/timers.js:46:19)
    at Timeout.timeoutTimeout [as _onTimeout] (/Users/vitch/Library/Caches/Cypress/8.3.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/timers.js:76:13)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)


  (Results)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Tests:        1                                                                                โ”‚
  โ”‚ Passing:      0                                                                                โ”‚
  โ”‚ Failing:      1                                                                                โ”‚
  โ”‚ Pending:      0                                                                                โ”‚
  โ”‚ Skipped:      0                                                                                โ”‚
  โ”‚ Screenshots:  0                                                                                โ”‚
  โ”‚ Video:        false                                                                            โ”‚
  โ”‚ Duration:     34 seconds                                                                       โ”‚
  โ”‚ Spec Ran:     connection-spec.js                                                               โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ โœ–  connection-spec.js                       00:34        1        -        1        -        - โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โœ–  1 of 1 failed (100%)                     00:34        1        -        1        -        -  

Cypress run results: 1 total tests, 0 passed, 1 failed

Error launching browser

Apologies if this is redundant, but I haven't seen any reference to this in the issues. using @synthetixio/[email protected]

The launchOptions object returned by your plugin's before:browser:launch handler contained unexpected properties:

width
height
resizable
launchOptions may only contain the properties:

preferences
extensions
args

image

I'm passing in my env vars with dotenv-cli and the test I'm attempting to run is just attempting to visit the landing page of a project:

describe('Metamask', () => {
  before(() => {
    cy.visit('/')
  })
})

How to connect Account2 to my site

Hi!
I created the Account2 by cy.createMetamaskAccount
And cy.switchMetamaskAccount
But I cannot let the Account2 connect to my website.
How can I resolve this?
Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.