You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@jennifer-shehane Sure! Apologies for the lack of information earlier.
The code is the same as what you have, but after the test finishes, open the dev console in your browser and type window.screen.width
Previously (with version 13.x), this returned 300, but now the value stays unchanged.
This is crucial because our web app determines the screen size using this property (which, of course, is done without Cypress).
Let me know if you need more info.
Thank you for prompt response!
@jennifer-shehane
Sorry for misleading you, I expect this code to work:
beforeEach(()=>{Cypress.on('window:before:load',win=>{(winasany).screen=newProxy(win.screen,{get(target,prop){if(prop==='width'||prop==='availWidth'){return300;}returntarget[prop];},});});});it('should have width',()=>{cy.intercept('mytest.com**',{body: `<html><head></head><body>Hello</body></html> <script> console.log('window.screen.width', window.screen.width); // here should be 300 </script>`,});cy.visit('mytest.com');cy.window().its('screen').its('width').should('eq',300);});
But seems it works identically in both versions 13.17 and 14.0. Seems there is something else with our configuration
I'll update you when find it.
Current behavior
With cypress 13.x the following code worked well (proxy was applied and when the app asked for
window.screen.width
it returned proper mocked value) :After upgrading to 14.x this stopped working and only works in
Cypress.on('window:load', (win: Window) => {
Desired behavior
The following code to make changes to window object:
Test code to reproduce
in setup.ts / setup.js / index.ts / e2e.ts
add thie following:
Start any test with cypress and in dev console write
window.screeen.width
- it should show '300'.Cypress Version
14.0.1
Node version
18.12.0
Operating System
macOS 15.3 / linux Debian
Debug Logs
Other
No response
The text was updated successfully, but these errors were encountered: