How to switch userAgent in the middle of tests #17558
Replies: 2 comments
-
Good afternoon, I have a similar need to test the following scenario :
It seems this was possible using the parameter user-agent in Cypress 3.3 but it does no longer work https://stackoverflow.com/questions/51048880/is-there-a-programmatic-way-to-change-user-agent-in-cypress-io Do you have a way to do this test? |
Beta Was this translation helpful? Give feedback.
-
You should probably follow this issue: #2100 Forget this:
because I just tested this in Cypress 10.3.1 and whenever in your test you execute cy.reload() or cy.visit('...') (without onBeforeLoad), the userAgent will jump back to the default in cypress.config.js (or cypress.json for Cypress < 10). The only way I saw so far is to start Cypress explicitly with another config, i.e. And then follow instructions here https://docs.cypress.io/guides/guides/cross-browser-testing#Running-Specific-Tests-by-Browser and https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Test-Configuration on how to configure tests to only run with a specific browser. And maybe just seperate mobile tests from desktop tests by folder and set different "specPattern" (or "testFiles" in Cypress < 10) in your cypress.config.js. Not sure if there are other ways.. maybe @lmiller1990 has some other ideas? :-D I'll bring in some other ideas into issue #2100 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I have below test scenario
open website on desktop > fill information > get the link > open link on mobile > continue the flow
So I need to switch between desktop and mobile in the middle of tests
Based on docs here , userAgent changes are ignore in the run time
I have tried many different like below to change userAgent none is working, and userAgent is read from cypress.json
Wondering what is the solution to be able to write my tests?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions