Finney14
Finney14

Reputation: 331

Cypress - Cannot open a button link that leads to a new tab

I am trying to click a button that links to new tab in order to continue testing the journey. I know cypress doesn't support multi-tab so I am hoping there is a way to open it in the same tab. The problem is the button doesn't use an <a> tag and seems to be dynamically generating the link. Code below...

<button _ngcontent-c14="" aria-label="download-data" class="download-button btn btn-default col-sm-3" value="download data" id="search-download-button-0-08062604-94b4-432c-8f36-19bb2757cadf"></button>

I cannot remove the target attribute because there isn't one. Apologies if I missed any details, this is my first post and i am relatively new to Cypress

Upvotes: 2

Views: 918

Answers (1)

Radha
Radha

Reputation: 106

As specified in Cypress documentation "Because Cypress runs in the browser, it will never have multi-tabs support."

https://docs.cypress.io/guides/references/trade-offs.html#Multiple-tabs

Also there are other Possible solutions suggested at below:

https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__tab-handling-links/cypress/e2e/tab_handling_anchor_links_spec.cy.js

To solve this problem, break the test cases into smaller step:

  1. Are you able to identify button by given attributes ?
  2. Can you click on the button ?
  3. What to verify on New Tab once button is clicked ?
  4. Can that verification be done without switching to another tab?
  5. Can you identify the URL in new tab openend?

Upvotes: 2

Related Questions