Examples of get the url within your application in Cypress, for a full reference of commands, go to docs.cypress.io
To get window.location
, use the cy.location()
command.
cy.location().should((location) => {
expect(location.hash).to.be.empty
expect(location.href).to.eq('https://example.cypress.io/commands/location')
expect(location.host).to.eq('example.cypress.io')
expect(location.hostname).to.eq('example.cypress.io')
expect(location.origin).to.eq('https://example.cypress.io')
expect(location.pathname).to.eq('/commands/location')
expect(location.port).to.eq('')
expect(location.protocol).to.eq('https:')
expect(location.search).to.be.empty
})
To get the current URL, use the cy.url()
command.
cy.url().should('eq', 'https://example.cypress.io/commands/location')