Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YakovL opened this issue Jul 9, 2023 · 4 comments
Labels
bug 🐛 Something isn't working

Comments

@YakovL
Copy link
Contributor

YakovL commented Jul 9, 2023

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

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 YakovL added the bug 🐛 Something isn't working label Jul 9, 2023
@YakovL YakovL changed the title tasksetupMetamask fails with ECONNREFUSED 127.0.0.1:9222 cy.task('setupMetamask') failed with ECONNREFUSED 127.0.0.1:9222 ("before all" hook) Jul 9, 2023
@YakovL
Copy link
Contributor Author

YakovL commented Jul 11, 2023

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
Copy link
Contributor Author

YakovL commented Jul 11, 2023

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.

@defiled
Copy link

defiled commented Jun 30, 2024

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.

@YakovL
Copy link
Contributor Author

YakovL commented Aug 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants