Is there a way to automate multiple tabs using cypress? e.g. After login to my webpage, I get redirected to another tab. So, I would like to automate login in 1st tab and then perform other testing activities in another tab(after login redirect) using cypress testing tool.


From the Cypress site:

Because Cypress runs in the browser, it will never have multi-tabs support. We do have access to the browser automation APIs to actually switch tabs, but there is no reason for us to ever expose them.

Most of the time this use case is needed when users click an that opens a new tab. Users then want to switch to that tab to verify that the content loaded. But, you shouldn’t need to do this. In fact we have recipes of showing you how to test this without multiple tabs.

The mentioned recipe is here.

  • 1
    Cypress's docs blew my mind when I read that. Obviously there's no sense in testing the browser's capabilities of opening a new tab, but many apps make use of tabs as part of their navigation. Have these people really never had to test behavior in a tab after it's opened? That's very distinct from testing that a tab has opened. At any rate, if it helps someone else: I'm able to get around this in my use case by navigating directly to the path the tab would normally open using cy.request(). – Jerreck May 27 '20 at 16:50
  • Also, here's a better link to their docs where they discuss this: docs.cypress.io/guides/references/trade-offs.html#Multiple-tabs – Jerreck May 27 '20 at 16:50
  • When executing n number of test cases, can we control the browser open and close pattern in Cypress? Say open and close for each test cases – Ashok kumar Ganesan Dec 21 '20 at 7:47

João Farias provided a good link related to your direct question about multiple tabs, but since you mentioned that your specific scenario is logging in, there may be another approach you can use:

The preferred way to handle login in Cypress is to bypass the UI and get login credentials directly from the backend--see this list of recipes. Of course, if you're testing login itself that doesn't really test it, but the majority of the time login is just setup for testing the rest of your site, as you described.

Also see this section of the Cypress getting started guide. As they describe there, it's good to use the UI for testing login itself, but otherwise, logging in using the UI will generally make your tests much slower than using the backend directly. The ability to use features like cy.request and cy.task to directly manipulate the backend state is, in my experience, one of the major advantages of using Cypress.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.