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

ERR_FAILED (-2) when loading new window Electron 102 (headless) via CLI #23835

Closed
MvRiele opened this issue Sep 15, 2022 · 6 comments
Closed

Comments

@MvRiele
Copy link

MvRiele commented Sep 15, 2022

Current behavior

Test uses cy.window().then(win => { cy.spy(win, 'open').as('windowOpen'); }); and cy.waitUntil(() => cy.get('@windowOpen').should('be.called')); to check if opening a window is triggered.

When running in CLI Electron 102 (headless) an error is given:

ERR_FAILED (-2) loading 'https://www.testcode.com/?title=test' Error: ERR_FAILED (-2) loading 'https://www.testcode.com/?title=test' at rejectAndCleanup (node:electron/js2c/browser_init:161:7647) at EventEmitter.stopLoadingListener (node:electron/js2c/browser_init:161:8022) at EventEmitter.emit (node:events:526:28) at EventEmitter.emit (node:domain:475:12)

When i run in chrome, there is no error and the test runs fine

Desired behavior

No error given

Test code to reproduce

Test uses cy.window().then(win => { cy.spy(win, 'open').as('windowOpen'); }); and cy.waitUntil(() => cy.get('@windowOpen').should('be.called')); to check if opening a window is triggered.

Cypress Version

10.8.0

Node version

6.14.13

Operating System

windows 11 PRO

Debug Logs

No response

Other

No response

@ZachJW34
Copy link
Contributor

ZachJW34 commented Sep 16, 2022

We recommend stubbing window.open rather than spying on it as we don't support running Cypress commands inside another window (popup or new tab), see comment. So you can replace the cy.spy with cy.stub and you should be able to verify that the stub was called.

That said, Cypress should not be crashing when you call this function and we should print a nice error message in the UI in this case. I was able to reproduce this error with the code snippets you provided. Thanks for the issue @MvRiele, let me know if the workaround works for you.

@DavesPlanet
Copy link

we are experiencing this same error with electron (apparently not chrome) on a simple

cy.get("#foo").click();
cy.url().should('includ','http://bar');

when the thing being clicked causes a pop-up window to download a pdf

@StephanGuingor
Copy link

StephanGuingor commented Jan 6, 2023

I'll leave this here, we are also experiencing this issue. By using cy.stub instead of cy.spy worked fine.
Although this should be marked as a bug, as it should not crash, it happend on Electron (headless) 106

An example on how you can test the window by stubbing:

const stub = cy.stub().as('open')
cy.on('window:before:load', (win) => {
            cy.stub(win, 'open').callsFake(stub)
})

And then to verify it got called cy.get("@open").should("be.called")

@flotwig
Copy link
Contributor

flotwig commented Feb 27, 2023

This is seemingly a duplicate of #18547, closing

@flotwig flotwig closed this as completed Feb 27, 2023
@benfenglee
Copy link

Damn it, I showed up, and I don't know how to fix it, okay

Error: ERR_FAILED (-2) loading 'http://localhost:8090/'
at rejectAndCleanup (node:electron/js2c/browser_init:2:84559)
at WebContents.stopLoadingListener (node:electron/js2c/browser_init:2:84946)
at WebContents.emit (node:events:526:35) {
errno: -2,
code: 'ERR_FAILED',
url: 'http://localhost:8090/'
}

@Willey1986
Copy link

@benfenglee and everyone else coming here from google.

We had a similar issue, cypress simply crashed on startup with a similar message. It seems like cypress has problems when the computer is set to enery saving mode (Windows 11).

Perhaps the startup takes to long an cypress decides to kill the electron process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants