1

I am using Cypress to click a link on the Homepage which opens the respective page in the new window. I am not able to identify any element on this page. I am doing this to verify that the click opens the correct page.

I saw the link: Access a new window - cypress.io which didn't help much to answer the problem.

Please suggest if there is some way to test this.

I have tried few things like:

cy.window().contains('.div.trItem')
cy.window().its('.trValue).should('eq','SomeHeading')
cy.url().should('include', '/theLink1.html/')

Expected: - Clicking link open the correct page in new window - Identify URL in new window includes some text - Certain text displays on the new window

Sheetal
  • 11
  • 2

1 Answers1

0

First of all, you can't access to another tab or window with Cypress. Consider to separate your test cases. For example, in one test you could check that a element contains href attribute with expected url and target attribute with _blank. Like this:

it('contains valid a element', () => {
  cy.visit('https://example.cypress.io/')
  cy.contains('Cypress.io').should('have.attr', 'href', 'https://www.cypress.io').should('have.attr', 'target', '_blank')
})

And in second test check that your other page contains expected text.

Danny
  • 682
  • 1
  • 11
  • 21