← Back to library
Cypressassertionsintermediatev10+

Assert page title

Use cy.title() to retrieve the document title and chain assertions on it.

1it('page has the correct document title', () => {
2  cy.visit('/');
3
4  // cy.title() returns document.title — chain .should() to assert it
5  cy.title().should('eq', 'SnipQA — Playwright & Cypress Snippet Library');
6
7  // Partial match with 'include'
8  cy.title().should('include', 'SnipQA');
9
10  // After navigating to another route, verify the title updated
11  cy.get('a[href="/pricing"]').click();
12  cy.title().should('include', 'Pricing');
13});
#cy.title#page title#document title#SEO