skip to Main Content

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

  1. user logs in to chrome.
  2. user performs some actions after login.
  3. user tries to login in the firefox or any other browser.
  4. user should get mail for verification OTP in firefox
  5. user enters OTP and it should get login

3

Answers


  1. 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

    Login or Signup to reply.
  2. 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 sake

    Login or Signup to reply.
  3. Since 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.

    // e2e-run-check-otp-after-authentication.js
    const cypress = require('cypress')
    
    cypress.run({
      spec: './cypress/e2e/examples/authentication.cy.js',
      browser: 'chrome',
    })
    
    cypress.run({
      spec: './cypress/e2e/examples/check-otp.cy.js',
      browser: 'firefox',
    })
    

    The above is a nodeJs script, by convention in the scripts folder of the project.

    You call it from the command line like this

    node e2e-run-check-otp-after-authentication.js
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search