0
0
Cypresstesting~10 mins

cy.url() assertions in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a webpage, clicks a link, and verifies the URL changes as expected using cy.url() assertions.

Test Code - Cypress
Cypress
describe('URL Assertion Test', () => {
  it('should navigate to Actions page and verify URL', () => {
    cy.visit('https://example.cypress.io')
    cy.get('a[href="/commands/actions"]').click()
    cy.url().should('include', '/commands/actions')
    cy.url().should('eq', 'https://example.cypress.io/commands/actions')
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.cypress.io'Browser shows the Cypress example homepage-PASS
3Finds link with href '/commands/actions' using cy.getLink element is found on the page-PASS
4Clicks the found linkBrowser navigates to the Actions commands page-PASS
5Asserts URL includes '/commands/actions' using cy.url().should('include', ...)Current URL is 'https://example.cypress.io/commands/actions'URL contains '/commands/actions'PASS
6Asserts URL equals 'https://example.cypress.io/commands/actions' using cy.url().should('eq', ...)Current URL is exactly 'https://example.cypress.io/commands/actions'URL equals 'https://example.cypress.io/commands/actions'PASS
Failure Scenario
Failing Condition: The link with href '/commands/actions' is missing or the URL does not update correctly after click
Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.url().should('include', '/commands/actions') check?
AThe page title includes '/commands/actions'
BThe current URL contains the string '/commands/actions'
CThe URL exactly equals '/commands/actions'
DThe page has a link with href '/commands/actions'
Key Result
Always verify the URL after navigation to confirm the page changed as expected. Using cy.url() assertions helps catch navigation issues early.