Cypress: window.alert hold page load forever even chromeWebSecurity set to false

Created on 8 May 2019  路  6Comments  路  Source: cypress-io/cypress

Current behavior:

My app require to test third-party payment, so I have to setup chromeWebSecurity to false.

After redirect to different superdomain, the alertbox won't be auto accepted.

An_embedded_page_at_127_0_0_1_8081_says_and_cypress_alert_issue_and_alert_html_鈥擾cypress_alert_issue

Desired behavior:

The alert box should be auto accepted.

Steps to reproduce: (app code and test code)

Here is the repo to reproduce, steps in the README.md.

https://github.com/zackexplosion/cypress-alert-issue

test code is very simple.

describe('alert will hold page load', function() {
  it('forever', function() {
    // Just a blank page. 
    cy.visit('http://127.0.0.1:8080')

    // after form submit, it will redirect to http://127.0.0.1:8081/alert, and the alertbox won't be accepted.
    cy.get('#_form_aiochk').submit()
  })
})

Versions

Cypress: 3.2.0
MacOS: 10.13.6
Browser: Chrome 74.0.3729.131

ready for work bug

Most helpful comment

I can recreate this from this repo: https://github.com/zackexplosion/cypress-alert-issue Likely does not work because the alert is being called from the new url being navigated to.

All 6 comments

Hey @zackexplosion,

Cypress should auto-accept window alerts.

Can you try to set up an event listener to see if we are getting the alert event here? Make sure your DevTools are open to hit debugger or console.log.

cy.on('window:alert', () => {
  debugger
})

I do suspect this is not hitting because the alert is coming from a different domain than you are currently on though.

Let me know what result you get here and perhaps we can think of a workaround if it is not hitting the event listener.

Hi @jennifer-shehane ,

By change the spec.js to this.

describe('alert will hold page load', function() {
  it('forever', function() {
    cy.on('window:alert', () => {
      console.log('hello from cy event')
    })

    cy.visit('http://127.0.0.1:8080')

    cy.on('window:alert', () => {
      console.log('hello from cy event2')
    })

    cy.get('#_form_aiochk').submit()

    cy.on('window:alert', () => {
      console.log('hello from cy event3')
    })
  })
})

The event never fired.

image

Thanks for your reply.

I can recreate this from this repo: https://github.com/zackexplosion/cypress-alert-issue Likely does not work because the alert is being called from the new url being navigated to.

I can recreate this from this repo: https://github.com/zackexplosion/cypress-alert-issue Likely does not work because the alert is being called from the new url being navigated to.

Yes, that is the problem. Thanks for the reply.

have Any solution锛烮 hive the same problem too...

Did anyone find a solution for this?

Was this page helpful?
0 / 5 - 0 ratings