Cypress: window.Cypress is undefined when running CLI with Electron

Created on 22 Aug 2018  Â·  11Comments  Â·  Source: cypress-io/cypress

Current behavior:

window.Cypress is undefined when running in Electron via CLI

Desired behavior:

window.Cypress should be defined

Steps to reproduce:

Open any project and add a conditional to the view that will add a tag if window.Cypress is defined.

i.e. for react

{window.Cypress && <p data-cy="windowTest">window.Cypress is defined</p>}

add a cypress test to your spec file checking for the presence of the tag

cy.get('[data-cy=windowTest]')

Run via the cli cypress run my_spec.js this runs in Electron by default. Tag is not present.

Run via cli cypress run my_spec.js --browser chrome this runs it in Chrome. It works.

Run cypress open and click the spec file. It works.

This issue is a pain point because video recording isn't supported in Chrome, so it'll be difficult to debug issues when it runs in our CI. We have to use window.Cypress in order to authenticate our automation user properly.

Versions

Observed in both v2 and v3.

All 11 comments

Note: this is a sporatic issue — It will generally work in electron with the first spec, but subsequent specs that are dependent on window.Cypress being present, will generally fail.

I'm afraid those steps to reproduce don't really prove that window.Cypress is undefined. They just prove that the element has not been rendered, which could be caused by something else within your app.

Can you try the following test to verify that window.Cypress is indeed undefined:

cy.window().its('Cypress').should('be.an', 'object')

@chrisbreiding Still undefined with that test instead. Noticed it's only happening when we run it against our QA site. Works fine locally.

Hey @paulmoliva, is it possible to provide a public url that we could visit in Cypress to see this behavior? Or you could provide a reproducible repo? We'll need to be able to reproduce this to address the issue. Thanks!

Also just ran into this issue... is there a better way to detect testing environment?

Nevermind, it was a pageload issue

Unfortunately we'll have to close this issue since no reproducible example is provided. Please comment with a reproducible example to consider reopening.

window.Cypress on Electron browser is undefined.

I'm running this test

cy.window().its('Cypress').should('eq', true)

Screenshot 2019-10-17 at 16 02 36

Update:

Also happens with --browser chrome, it happens sometimes in chrome, a few minutes ago it worked.

Please ensure you are visiting a valid url first before running this assertion, otherwise there is no window that Cypress could be attached to. The test below passes for me in Electron and chrome.

it('has Cypress defined', () => {
  cy.visit('index.html')
  cy.window().its('Cypress').should('be.an', 'object')
})

I have written 5 tests using cypress. When I do 'cypress run', Only the first test passes and all other tests fail at the line cy.window().its('Cypress').should('be.an', 'object'). Here is a screenshot
image

PS: Same test code works fine when run individually using 'cypress open'

@Gurubg1 I'm not able to recreate this. From the screenshot, it looks like you're calling cy.window() then cy.visit() and chaining 'its' off of this.

Screen Shot 2020-03-25 at 6 09 16 PM

My test code:

it('test', () => {
  cy.window()
  cy.visit('index.html').its('Cypress').should('be.an', 'object')
})

I see you're using the Cypress cucumber plugin - try removing cucumber and run again, it may be an issue isolated to that plugin.

Please also try to update to the current version of Cypress.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dkreft picture dkreft  Â·  3Comments

egucciar picture egucciar  Â·  3Comments

igorpavlov picture igorpavlov  Â·  3Comments

zbigniewkalinowski picture zbigniewkalinowski  Â·  3Comments

jennifer-shehane picture jennifer-shehane  Â·  3Comments