synpress icon indicating copy to clipboard operation
synpress copied to clipboard

`cy.task('setupMetamask')` failed with ECONNREFUSED 127.0.0.1:9222 ("before all" hook)

Open YakovL opened this issue 2 years ago • 4 comments

Describe the bug My setup worked for some time, but at some point it started failing with this error in Cypress UI:

tasksetupMetamask, Object{5} (uncaught exception)CypressError: cy.task('setupMetamask') failed with the following error:

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

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

and this error in Cypress cli output:

  1. Test of Synpress and Metamask with a DApp from a tutorial "before all" hook for "Open, connect, confirm": CypressError: Cypress test was stopped while running this command.

Because this error occurred during a before all hook we are skipping all of the remaining tests. at cypressErr (http://localhost:60794/__cypress/runner/cypress_runner.js:164516:18) at Object.errByPath (http://localhost:60794/__cypress/runner/cypress_runner.js:164571:10) at http://localhost:60794/__cypress/runner/cypress_runner.js:166184:80

Seemingly I haven't changed anything (moreover, I've seen this error before, it took place and then disappeared, and I didn't get what was the cause), so I'm really puzzled with it. I've tested my reference setup and the problem is reproduced there, too!

As I've found this Cypress issue, I've also tried to bump Cypress version to 12.17.0, but it didn't help.

To Reproduce May be you'll get the same result with:

  1. Clone https://github.com/YakovL/synpress-cucumber , run npm i
  2. Run npm run test:e2e

Expected behavior With the repo above, I expect the tests to run as previously (succeed).

Desktop (please complete the following information):

  • OS: Windows 10 Pro x64
  • Synpress version: 12.17.0
  • Node.js version: 18.16.0
  • Chrome 114.0.5735.199

Additional context

  • this may be related to #449, drptbl hasn't responded on whether that one should be reopened, so here's a new issue;
  • this might be related, too: https://github.com/cypress-io/cypress/issues/5445.

Please let me know whether you can reproduce this issue, because reproducibility is hell with Cypress/Synpress, and knowing that somebody else can reproduce will help a lot.

YakovL avatar Jul 09 '23 16:07 YakovL

By the way, "error in Cypress cli output" above is that for the second feature (I haven't committed the other one in the reference setup repo); for the first one it seems to differ from time to time, but now it's

  1. Wishlist "before all" hook for "Seeing the wishlist button": 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:58865/__cypress/runner/cypress_runner.js:149497:81 at tryCatcher (http://localhost:58865/__cypress/runner/cypress_runner.js:18744:23) at http://localhost:58865/__cypress/runner/cypress_runner.js:13866:41 at tryCatcher (http://localhost:58865/__cypress/runner/cypress_runner.js:18744:23) at Promise._settlePromiseFromHandler (http://localhost:58865/__cypress/runner/cypress_runner.js:16679:31) at Promise._settlePromise (http://localhost:58865/__cypress/runner/cypress_runner.js:16736:18) at Promise._settlePromise0 (http://localhost:58865/__cypress/runner/cypress_runner.js:16781:10) at Promise._settlePromises (http://localhost:58865/__cypress/runner/cypress_runner.js:16857:18) at _drainQueueStep (http://localhost:58865/__cypress/runner/cypress_runner.js:13451:12) at _drainQueue (http://localhost:58865/__cypress/runner/cypress_runner.js:13444:9) at ../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:58865/__cypress/runner/cypress_runner.js:13460:5) at Async.drainQueues (http://localhost:58865/__cypress/runner/cypress_runner.js:13330:14)

I've also tried adding

userAgent: "synpress",
chromeWebSecurity: true,
defaultCommandTimeout: 30000,
pageLoadTimeout: 30000,
requestTimeout: 30000,

to config but it doesn't help.

Also, commenting out this feature doesn't affect the initial issue.

YakovL avatar Jul 11 '23 17:07 YakovL

Another thing to note is, Metamask doesn't get configured in its Chrome tab, like it used to be. Presumably the network issue is not being connect to Playwright.

Oh, yeah! Looking for 9222 in Playwright repo, I've found a discussion which suggested that the browser should be run with the --remote-debugging-port=9222 option. Googling a little more, I've found that some suggest to set it via env (CYPRESS_REMOTE_DEBUGGING_PORT=9222). I've added it to my Cypress env, and the problem is gone!

But I don't have answers to these questions:

  • why it was working previously without this?
  • what value is used otherwise? none? how can I look it up?

I've also assumed that I may have set this env var at some point earlier when I was tinkering Cucumber/Cypress/Synpress and that has somehow cached and applied after I've clean up my setup. But when I've set this variable, run, removed it and run again, I get the errors again, so this doesn't seem to be a valid hypothesis.

YakovL avatar Jul 11 '23 17:07 YakovL

It could also be your .env file. Are you setting NETWORK_NAME=localhost without running MetaMask locally? If so, the beforeAll() hook that Synpress adds is failing because it's looking to connect to MetaMask on that port and nothing is listening.

defiled avatar Jun 30 '24 16:06 defiled

I'm no longer working on that project, but as you can see from the reference repo, I had NETWORK_NAME set to 'Polygon Mainnet', so your guess doesn't seem to be correct

YakovL avatar Aug 15 '24 06:08 YakovL