My web app generates a UUIDv4 for every new 'post', and each post has its own URL like /posts/<uuid>
. I'm not able to predict what uuid gets generated, and therefore I'm unable to go back to a specific post that was created earlier during testing.
According to the docs, cy.url()
returns the URL as a string. I tried saving the URL using a .as()
, but it didn't work:
cy.url().as('postUrl');
// go somewhere else
cy.visit('@postUrl');
// ends up visiting `localhost:3000/@postUrl`
I saw in another SO question that I should use .then
on cy.url()
, but that didn't work either:
cy.url().then(url => url).as('postUrl');
// go somewhere else
cy.visit('@postUrl');
How do I save the current URL for use later?