NitzanZ
NitzanZ

Reputation: 43

How can I get part of url in Cypress

Im generating ids and then using id to cy.visit them , I wanna assert the generated id using cy.url().split('/') but I can not , Split works only for strings and cy.url() returns Chainable<string> , any other ways to do that ?

Upvotes: 4

Views: 3114

Answers (1)

GrayDwarf
GrayDwarf

Reputation: 2757

This should work. Swap out 0 for whatever index you need.

cy.url().then(url => {
  cy.log(url.split('/')[0])
});

Upvotes: 6

Related Questions