Cypress Title Command

Profile picture for user devraj

Using the Cypress title command, you can get the current page's title. The title command yields the document.title property of the current page.

Table of Content

  1. Syntax
  2. Rules
  3. Verify Exact Page Title
  4. Verify Page Title Contains
  5. Video Tutorial

Syntax

cy.title()
cy.title(options)

In options, you can pass in log and timeout objects.

Rules

  1. cy.title() requires being chained off of cy.
  2. cy.title() will automatically retry until all chained assertions have passed.
  3. cy.title() can time out waiting for assertions you've added to pass. 

Verify Exact Page Title

it.only('verify title', () => {
    cy.visit('https://www.programsbuzz.com')

    cy.title().should('eq', 'Online Technical Courses | ProgramsBuzz')
    cy.title().should('equal', 'Online Technical Courses | ProgramsBuzz')
    cy.title().should('equals', 'Online Technical Courses | ProgramsBuzz')
})

Here, eq, equal and equals are aliases.

Verify Page Title Contains

it.only('verify title', () => {
    cy.visit('https://www.programsbuzz.com')

    cy.title().should('include', 'ProgramsBuzz')
    cy.title().should('contain', 'ProgramsBuzz')
    cy.title().should('contains', 'ProgramsBuzz')
})

Here include, contain, contains are aliases.