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
- cy.title() requires being chained off of cy.
- cy.title() will automatically retry until all chained assertions have passed.
- 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.