Reputation: 3241
Is there a way I can access (and possibly edit) a global variable myVar
from the Cypress side?
To be clear, by global I mean it is defined in the document
object.
I tried through cy.window()
cy.window().then((win) => {
console.log(Cypress.$(win.document).myVar); //undefined
console.log(Cypress.$(win.document).get(0).myVar); //undefined
});
Upvotes: 1
Views: 922
Reputation: 1427
According to cypress docs here is the solution
it('equals bar', () => {
let foo
cy.window()
.then((win) => {
foo = win.foo
})
.then(() => {
// variable "foo" has been set
expect(foo).to.equal('bar') // test passes
})
})
Upvotes: 2