Consider the following Cypress test steps:
cy.visit('/page1')
cy.visit('/page2')
cy.go(-1)What page will Cypress be on after cy.go(-1) executes?
cy.visit('/page1') cy.visit('/page2') cy.go(-1)
Think about how browser history works when you visit pages and then go back.
After visiting '/page1' and then '/page2', the browser history has two entries. cy.go(-1) moves back one entry, so the browser goes back to '/page1'.
You have navigated back one page using cy.go(-1). Now you want to go forward one page using cy.go(1) and verify the URL is '/page2'. Which assertion is correct?
Check the Cypress documentation for the correct assertion method to check URL substring.
cy.url() returns the full URL string. Using should('include', '/page2') checks that the URL contains '/page2' anywhere, which is the correct way to verify partial URL matches.
Given the test steps:
cy.visit('/home')
cy.visit('/about')
cy.go(-2)Running cy.go(-2) causes the test to fail with a navigation error. Why?
Think about how many pages are in the browser history after two visits.
After visiting '/home' and then '/about', the history stack has two entries. Going back two pages means going before the first page, which is invalid and causes an error.
In Cypress, what is the behavior of cy.go() when called without any arguments?
Check the Cypress documentation for the default behavior of cy.go().
Calling cy.go() without arguments reloads the current page, acting like cy.reload().
You want to write a Cypress test that visits three pages in order: '/page1', '/page2', '/page3'. Then you want to go back twice and verify the URL is '/page1'. Which code snippet correctly implements this?
Remember that cy.url() returns the full URL, so exact equality may fail if the base URL is included.
Option D correctly goes back two pages and asserts the URL contains '/page1'. Using should('contain', '/page1') is safer than should('eq', '/page1') because the full URL includes the base domain.