← Back to library
Cypressassertionsadvancedv10+

Assert current URL

Use cy.url() to retrieve the full current URL and assert it after navigation or redirect.

1it('URL is correct after login redirect', () => {
2  cy.visit('/login');
3
4  cy.get('[name="email"]').type('user@test.com');
5  cy.get('[name="password"]').type('secret');
6  cy.get('[type="submit"]').click();
7
8  // cy.url() automatically retries — handles async redirects from SPAs
9  cy.url().should('include', '/dashboard');
10
11  // Exact match using baseUrl from cypress.config.js
12  cy.url().should('eq', Cypress.config('baseUrl') + '/dashboard');
13
14  // After further navigation
15  cy.get('a[href="/settings"]').click();
16  cy.url().should('match', /\/settings/);
17});
#cy.url#URL#location#redirect#navigation