0
0
Cypresstesting~10 mins

cy.go() for browser history in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test navigates between two pages using Cypress commands and then uses cy.go() to move back and forward in the browser history. It verifies that the URL changes correctly after each navigation step.

Test Code - Cypress
Cypress
describe('Test cy.go() browser history navigation', () => {
  it('should navigate back and forward in browser history', () => {
    cy.visit('https://example.cypress.io')
    cy.contains('type').click()
    cy.url().should('include', '/commands/actions')
    cy.go('back')
    cy.url().should('eq', 'https://example.cypress.io/')
    cy.go('forward')
    cy.url().should('include', '/commands/actions')
  })
})
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test startsBrowser is ready to open a page-PASS
2cy.visit('https://example.cypress.io')Browser opens https://example.cypress.io homepage-PASS
3cy.contains('type').click()Page navigates to the 'type' commands page-PASS
4cy.url().should('include', '/commands/actions')URL includes '/commands/actions'Verify URL contains '/commands/actions'PASS
5cy.go('back')Browser navigates back to the homepage-PASS
6cy.url().should('eq', 'https://example.cypress.io/')URL is exactly 'https://example.cypress.io/'Verify URL equals homepage URLPASS
7cy.go('forward')Browser navigates forward to the 'type' commands page-PASS
8cy.url().should('include', '/commands/actions')URL includes '/commands/actions' againVerify URL contains '/commands/actions' after forward navigationPASS
Failure Scenario
Failing Condition: The element with text 'type' is not found or the URL does not change as expected after navigation
Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.go('back') do in this test?
ANavigates to a new URL
BReloads the current page
CNavigates to the previous page in browser history
DCloses the browser tab
Key Result
Use cy.go() to simulate user navigation through browser history and verify URL changes to ensure correct page transitions.