1 year ago

#382813

test-img

Caio Grossi

How to handle multiple tabs in cypress

Im coding integration tests in a project with cypress. This is the flow in my projet:

  • You click at a buy button of a projeto;
  • When you click, open a new tab in checkout product

Only this, click at a button and open a new tab with the checkout screen. But as we know, cypress dont have suport for multiple tabs, so how can i handle it? What is the way to open this new url in the same tab?

Important to highlight that this button is not wrapped by any a tag, its just a button that when I click has a handleClick that open a new tab and do other stuff. Because of this, none of these https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__tab-handling-links/cypress/integration/tab_handling_anchor_links_spec.js solutions work for me.

I already tried this:

      cy.stub(win, "open")
        .callsFake((url, target) => {
          //@ts-ignore
          return win.open.wrappedMethod.call(win, url, "_self");
          //@ts-ignore
        })
        .as("open");
    });

but no success.

testing

cypress

integration-testing

0 Answers

Your Answer

Accepted video resources