Bird
0
0

You want to test that after visiting three pages, going back twice returns to the first page. Which Cypress code correctly tests this?

hard📝 Application Q8 of 15
Cypress - Navigation and URL
You want to test that after visiting three pages, going back twice returns to the first page. Which Cypress code correctly tests this?
Acy.visit('/page1') cy.visit('/page2') cy.go(2) cy.visit('/page3') cy.url().should('include', '/page1')
Bcy.visit('/page1') cy.go(-2) cy.visit('/page2') cy.visit('/page3') cy.url().should('include', '/page1')
Ccy.visit('/page1') cy.visit('/page2') cy.visit('/page3') cy.go(-2) cy.url().should('include', '/page1')
Dcy.visit('/page3') cy.go(-2) cy.visit('/page1') cy.url().should('include', '/page1')
Step-by-Step Solution
Solution:
  1. Step 1: Visit pages in correct order

    Visiting '/page1', then '/page2', then '/page3' builds the history stack correctly.
  2. Step 2: Use cy.go(-2) to go back two pages

    This moves from '/page3' back to '/page1'.
  3. Step 3: Assert the URL includes '/page1'

    The assertion confirms the browser is on the first page.
  4. Final Answer:

    cy.visit('/page1') cy.visit('/page2') cy.visit('/page3') cy.go(-2) cy.url().should('include', '/page1') -> Option C
  5. Quick Check:

    Visit pages, go back twice, check URL [OK]
Quick Trick: Visit pages first, then use cy.go(-n) to go back [OK]
Common Mistakes:
  • Calling cy.go(-2) before visiting pages
  • Using cy.go(2) to go back
  • Visiting pages after cy.go()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes