user2201789
user2201789

Reputation: 1203

cypress how to close the new window and back to main test window

I have written codes to click on hyperlink then check the new window URL.

   cy.get('a[href*="newlink"]').eq(0).click()
   cy.url().should('equal', 'https://www.google.com')

how do i close this window / or not close AND back to the original main test window?

Upvotes: 3

Views: 16694

Answers (3)

jake downs
jake downs

Reputation: 357

here's a solution i use for swapping between popup windows: https://github.com/jakedowns/CypressHelpers

it would need some tweaking to work directly with .click but it does enable cy.openWindow and a new cy.switchWindow / cy.closeWindow

under the hood it uses an undocumented cy.state('document') and cy.state('window') method for context-switching

Upvotes: 4

ABC123
ABC123

Reputation: 309

you can use cy.go('back')

see here

Upvotes: 0

hotpink
hotpink

Reputation: 3226

cy.go(direction, options)

See the documentation for examples

This works for the history in the same tab. Cypress does not support multiple tabs.

Upvotes: 1

Related Questions