Hi. `window.Cypress` is going undefined in some of...
# help
j
Hi.
window.Cypress
is going undefined in some of my cypress tests, and consequently
window.store
also stays undefined. For example, I have a test like this:
Copy code
js
describe("test", () => {
  it("test store", () => {
    cy.visit("/");
    cy.contains("Username").should("be.visible");
    cy.window().its("store").should("exist");
    cy.get(".asdasdasd", {timeout: 50000}).should("exist");
  });
});
The last command is supposed to always fail and trigger a 2nd retry. The frontend (a React app) has the following in the
index.tsx
file (runs in the "/" which page the test is visiting):
Copy code
js
// expose store when run in Cypress
if (window.Cypress) {
  window.store = store;
}
When I run the frontend in dev mode (yarn start) the test always passes. When I compile-all and build the frontend and put it in nginx, when I run this test in cli (headless) mode it passes the store in the first try, fails the second try; when I run the test in windowed mode it passes the store both times (after I cleared the "workbox" cache in dev tools; before it would fail in the 2nd try). When I reduce the timeout from 50000 to anything lower than around 42900 it starts to pass in every case (once I noticed a spam like this during that time coming in the e2e terminal:
Copy code
...
GET /static/media/index.30302fff.less 200 505.212 ms - -
GET /static/media/index.33bfc7b4.less 200 558.951 ms - -
GET /static/media/index.3887c08f.less 200 521.361 ms - -
GET /static/media/index.4d6a62b6.less 200 505.271 ms - -
GET /static/media/index.500df235.less 200 518.217 ms - -
GET /static/media/index.52c1dfea.less 200 507.734 ms - -
...
I think it's related to the cache I deleted, but no idea what it could mean). I have tried testing an older version of the frontend that worked, it still fails 2nd try. Any suggestions?
I added
cy.window().its("Cypress").should("exist");
before checking for the store and got this: > CypressError: Timed out retrying after 7000ms:
cy.its()
errored because the property:
Cypress
does not exist on your subject. > >
cy.its()
waited for the specified property
Cypress
to exist, but it never did. > > If you do not expect the property
Cypress
to exist, then add an assertion such as: > >
cy.wrap({ foo: 'bar' }).its('quux').should('not.exist')
Shouldn't it always be defined in cypress tests?