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

window:confirm event ignored by command line (but not UI) #1432

Closed
benschenker opened this issue Mar 7, 2018 · 5 comments
Closed

window:confirm event ignored by command line (but not UI) #1432

benschenker opened this issue Mar 7, 2018 · 5 comments

Comments

@benschenker
Copy link

benschenker commented Mar 7, 2018

  • Operating System: OSX 10.3.3
  • Cypress Version: 2.1.0
  • Browser Version: Chrome 64

Is this a Feature or Bug? Bug

Current behavior:

When a page fires a confirm command, the UI runner correctly handles this (as noted in https://docs.cypress.io/api/events/catalog-of-events.html#App-Events) but when running cypress run from the command line it just times out waiting for the load event.

Desired behavior:

As noted in https://docs.cypress.io/api/events/catalog-of-events.html#App-Events, when a window:confirm event is fired, the default action should be auto accept. This should work the same when run from the UI and from the command line. At minimum the cy.on('window:confirm') command should be used.

How to reproduce:

  • Run the test below using the UI cypress open and it will pass
  • Run the test below using the command line cypress run --spec path/to/test.spec.js and it will fail

Test code:

Cypress file

describe('Test window.confirm', () => {
  beforeEach(() => {
    cy.on('window:confirm', () => true); // this is unnecessary as it is the default behavior
  });

  it('should accept the confirm and successfully reload', function() {
    cy.visit(`path/to/test.html`);
    cy.reload();
  });
});

test.html

<html>
  <body>
    hello world
  </body>
  <script>
    window.onbeforeunload = () => confirm("test");
  </script>
</html>

Additional Info (images, stack traces, etc)

EDIT - See example: cypress-io/cypress-test-tiny#27

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Mar 7, 2018
@benschenker
Copy link
Author

Update: if I run with cypress run --browser chrome this works correctly... looks like it is related to the electron browser

@bsmithEG
Copy link

bsmithEG commented May 24, 2018

I also seem to be having this issue, but for a different event. The below works fine with chrome, but not with Electron in headed or headless mode:

    //tslint:disable
    Cypress.on("window:before:load", win => {
        console.log("called window before load")
        const script = win.document.createElement("script")
        const scripts = win.document.getElementsByTagName("script")[0] as HTMLScriptElement
        script.type = "text/javascript"
        script.src = `http://localhost:3030/testfile.min.js`
        if (scripts && scripts.parentNode) {
            scripts.parentNode.insertBefore(script, scripts)
        }
    })

@jennifer-shehane
Copy link
Member

duplicate of #2118

@jennifer-shehane jennifer-shehane removed stage: needs investigating Someone from Cypress needs to look at this labels Jan 16, 2019
@nikhilesh009
Copy link

i want to see the alert message but i am getting this message in cypress log"There are unsaved changes to this booking. Are you sure you want to do this?" and it auto accept alert

@jennifer-shehane
Copy link
Member

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

No branches or pull requests

4 participants