Current behavior
Attempting to log in to my application via google. When the page loads, window.Cypress has the expected value.
But after I get redirected back to my application from Google sign in, window.Cypress in my application is undefined
Desired behavior
That when I am redirected back from cy.origin window.Cypress value is persisted/not undefined.
Test code to reproduce
This is my test.
Should not, I even tried to assert that window.Cypress is an object, which it seems to be in the context of the test, but not the application. When I have a console.log(window.Cypress) in my application it's undefined.
login.cy.ts
export default describe('Login Page', () => {
beforeEach(() => {
cy.visit(`/login`);
cy.clearCookies();
cy.clearLocalStorage();
});
it('logs in via Google', () => {
cy.awaitPageLoad();
// click on google login button
cy.clickBtn('google-login');
cy.origin('https://accounts.google.com/', () => {
cy.get('#identifierId').type(Cypress.env('GOOGLE_LOGIN_EMAIL'));
cy.get('span').contains('Next').click();
Cypress.on('uncaught:exception', (err) => !err.message.includes('ResizeObserver loop limit exceeded'));
cy.get("[name='password']").type(Cypress.env('SOCIAL_LOGIN_PASSWORD'), { log: false, timeout: 20000, force: true });
cy.get('span').contains('Next').click();
cy.window().its('Cypress').should('be.an', 'object');
});
cy.window().its('Cypress').should('be.an', 'object');
cy.awaitPageLoad();
});
});
My tests fail as I am relying on window.Cypress to have a value so certain functions don't get triggered. i.e analytics.
I even tried
Cypress.on('window:before:load', (win) => {
win.CypressRunning = true;
});
And did a check for window.CypressRunning but it also becomes undefined even though I never explicitly set it to anything else rather than true
Here is my cypress.config.ts
cypress.config.ts
import { defineConfig } from 'cypress';
import flags from './cypress/fixtures/flags.json';
import testOrder from './cypress/fixtures/test-order.json';
require('dotenv').config({ path: `.env` });
const order = testOrder.map((t) => `**/${t}.{cy,spec}.{js,jsx,ts,tsx}`);
export default defineConfig({
e2e: {
specPattern: [...order, '**/*.{cy,spec}.{js,jsx,ts,tsx}'],
setupNodeEvents(on, config) {
config.env.DEV_URL = process.env.CYPRESS_DEV_URL;
config.env.GOOGLE_LOGIN_EMAIL = process.env.GOOGLE_LOGIN_EMAIL;
config.env.SOCIAL_LOGIN_PASSWORD = process.env.SOCIAL_LOGIN_PASSWORD;
config.video = false;
config.screenshotOnRunFailure = false;
config.experimentalModifyObstructiveThirdPartyCode = true;
const excludeSpecPattern = ['**/1-getting-started/*', '**/2-advanced-examples/*'];
if (config.isTextTerminal) {
excludeSpecPattern.push('**/all.{cy,spec}.{js,jsx,ts,tsx}');
}
config.excludeSpecPattern = excludeSpecPattern;
on('before:browser:launch', (browser, launchOptions) => {
if (browser && (browser?.name === 'chromium' || browser?.name === 'chrome')) {
flags.forEach((flag) => {
if (!launchOptions.args.includes(flag)) launchOptions.args.push(flag);
});
}
return launchOptions;
});
return config;
},
},
});
Cypress Version
12.3.0
Node version
16.14.2
Operating System
macOS 12.6
Debug Logs
No response
Other
No response
Current behavior
Attempting to log in to my application via google. When the page loads,
window.Cypresshas the expected value.But after I get redirected back to my application from Google sign in,
window.Cypressin my application isundefinedDesired behavior
That when I am redirected back from
cy.originwindow.Cypressvalue is persisted/not undefined.Test code to reproduce
This is my test.
Should not, I even tried to assert that
window.Cypressis an object, which it seems to be in the context of the test, but not the application. When I have aconsole.log(window.Cypress)in my application it'sundefined.login.cy.ts
My tests fail as I am relying on
window.Cypressto have a value so certain functions don't get triggered. i.e analytics.I even tried
And did a check for
window.CypressRunningbut it also becomesundefinedeven though I never explicitly set it to anything else rather thantrueHere is my
cypress.config.tscypress.config.ts
Cypress Version
12.3.0
Node version
16.14.2
Operating System
macOS 12.6
Debug Logs
No response
Other
No response