Skip to main content

Cypress Title Command

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.

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. 

Example 

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.

Cypress Verify Page Title

Tags
Submitted by tgoswami on September 13, 2021

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.