Saad Usmani
Saad Usmani

Reputation: 21

How to assert a url in cypress

Hi i want to assert a url which increases on every save. Say a new job is created the url changes from job/1 to job/2. There is a increment on every newly created job.

Upvotes: 2

Views: 8218

Answers (3)

Baronvonbirra
Baronvonbirra

Reputation: 819

You can assert the whole URL with

cy.url().should('eq', 'http://localhost:8000/users/1/edit') // => true

Or just a part of it with

cy.url().should('include', '/users/1/edit') // => true

In your case, you could use:

cy.url().should('include', 'job/')

Upvotes: 4

Evgenii Bazhanov
Evgenii Bazhanov

Reputation: 926

or you can also assert specific URL search params like this:

cy.location().should(loc => {
   expect(loc.pathname).to.equal('/job/1')
})

read original docs

Upvotes: 2

Krupal Vaghasiya
Krupal Vaghasiya

Reputation: 550

Verify URL like

cy.url().should('eq', 'http://localhost:8000/users/1/edit')

You can check official cypress documentation here

Upvotes: 0

Related Questions