I have one file authentication.cy.ts where I am performing all the specs related to authentication. I have a scenario where I want to log in user at the same time in a different browser.
I know we can directly give a browser option while running the cypress test. In my case, I can’t give it because it should be ongoing. I have gone through this documentation https://docs.cypress.io/guides/guides/cross-browser-testing and didn’t find anything similar.
My flow is like below
- user logs in to chrome.
- user performs some actions after login.
- user tries to login in the firefox or any other browser.
- user should get mail for verification OTP in firefox
- user enters OTP and it should get login
3
Answers
For your use case, it may be easier to switch sessions (or logout) within the test, rather than switching browsers. Your session management could include clearing cookies related to remembering prior users.
See the Cypress documentation here: https://docs.cypress.io/api/commands/session#Switching-sessions-inside-tests
Cypress indeed doesn’t support such stuff and it would be very resource-intensive (considering Cypress already is very resource intensive)
What you might try is launching a puppeteer/playwright process via
cy.task
, it can be safely integrated in your config file just for this sakeSince you are swapping browsers, and Cypress runs the app inside an
iframe
in a particular browser, one option is to use the Module API to perform two different browser tests in one sequence.The above is a nodeJs script, by convention in the
scripts
folder of the project.You call it from the command line like this