ChainSafe / dappeteer

[DEPRECATED]🏌🏼‍E2E testing for dApps using Puppeteer + MetaMask
Other
491 stars 151 forks source link

TimeoutError: setupMetaMask doesn't work with Jest #297

Open undefinedlol opened 1 year ago

undefinedlol commented 1 year ago

Describe the bug

import { launch, setupMetaMask } from '@chainsafe/dappeteer';

 browser = await launch({
    headless: true,
    automation: 'puppeteer',
    puppeteerOptions: {
      ignoreHTTPSErrors: true,
      args: ['--no-sandbox', `--window-size=1440,1024`],
      defaultViewport: {
        width: 1440,
        height: 1024,
      },
    },
  });

  metamask = await setupMetaMask(browser, {
    seed: 'xxxx',
    password: '123456',
    showTestNets: true,
  });

 page = await browser.newPage();
  await page.goto('http://localhost:8000/');

always get errors like

TimeoutError: Waiting for selector `[data-testid="onboarding-import-wallet"]` failed: Waiting failed: 20000ms exceeded

@chainsafe/dappeteer Version: 5.0.1 dappeteer: 19.6.3

moshmage commented 1 year ago

Same, but with [data-testid="metametrics-i-agree"] instead of [data-testid="onboarding-import-wallet"]

TimeoutError: Waiting for selector `[data-testid="metametrics-i-agree"]` failed: Waiting failed: 20000ms exceeded
    at Timeout.<anonymous> (C:\Users\moshm\WebstormProjects\wn-ui\node_modules\puppeteer-core\lib\cjs\puppeteer\common\WaitTask.js:72:37)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

I've also noticed that sometimes the first page that loads is not an "i agree" but instead the "import-wallet"

mint-pz commented 12 months ago

Any solutions here? I got the same error as @moshmage

mint-pz commented 11 months ago

Hey @undefinedlol, Can I know if you tested it with mocha? Did it work then?

mint-pz commented 11 months ago

I don't get these issues anymore by using this config: https://github.com/ChainSafe/dappeteer/blob/master/docs/JEST.md#custom-example-without-preset

But you may get some others and here is my workaround:

1. environment.js

const NodeEnvironment = require('jest-environment-node').TestEnvironment

2. Have trouble starting metamask: https://github.com/ChainSafe/dappeteer/issues/311#issuecomment-1672721553

System: