Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 267
NitzanZ Avatar asked Oct 23 '25 14:10

NitzanZ


1 Answers

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

cy.url().then(url => {
  cy.log(url.split('/')[0])
});
like image 193
GrayDwarf Avatar answered Oct 26 '25 05:10

GrayDwarf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!