Bird
0
0

Given the following Cypress commands:

medium📝 Predict Output Q4 of 15
Cypress - Navigation and URL
Given the following Cypress commands:
cy.visit('/home')
cy.visit('/about')
cy.go(-1)
cy.url()

What URL will cy.url() return?
A'/about'
BAn error occurs
C'/contact'
D'/home'
Step-by-Step Solution
Solution:
  1. Step 1: Trace the navigation commands

    First, the test visits '/home', then '/about'. The browser history stack is ['/home', '/about'].
  2. Step 2: Apply cy.go(-1)

    This moves back one page, so the current page is '/home'.
  3. Final Answer:

    '/home' -> Option D
  4. Quick Check:

    cy.go(-1) moves back to '/home' URL [OK]
Quick Trick: cy.go(-1) moves back to previous visited URL [OK]
Common Mistakes:
  • Assuming cy.go(-1) reloads current page
  • Expecting cy.url() to return '/about'
  • Thinking cy.go(-1) causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes