Cypress: Properties set on the window object are becoming undefined.

Created on 15 Aug 2018  路  3Comments  路  Source: cypress-io/cypress

Current behavior:

When setting a property on the window object, it is not available to the running application.

Desired behavior:

The property set on the window object should persist and the running application should be able to access it.

Steps to reproduce:

  • Set a property on the window object with the following code
  • Either log the property in your application or in the developer tools console
  • Observe as the property is undefined

cy.window().then(window => window.disableIntercom = true);

Versions

Cypress v3.0.3
Chrome 59 I think

Most helpful comment

log the property in your application

This depends on when you log in your application. Your app may load and hit the console.log before the property is being set in your test. Your best bet is to use the onBeforeLoad callback of cy.visit:

cy.visit('/', {
  onBeforeLoad (win) {
    win.disableIntercom = true
  }
})

in the developer tools console

Since your app runs in an iframe, you may need to switch to it so that window is your app's window and not the 'top' window that Cypress runs in.

window-log

All 3 comments

log the property in your application

This depends on when you log in your application. Your app may load and hit the console.log before the property is being set in your test. Your best bet is to use the onBeforeLoad callback of cy.visit:

cy.visit('/', {
  onBeforeLoad (win) {
    win.disableIntercom = true
  }
})

in the developer tools console

Since your app runs in an iframe, you may need to switch to it so that window is your app's window and not the 'top' window that Cypress runs in.

window-log

Thanks for the info @chrisbreiding I did not see the window switcher in the developer tools, that should help.

@chrisbreiding thank you worked perfectly

Was this page helpful?
0 / 5 - 0 ratings