I need to visit a URL that redirects twice to different origins. e.g:
domain-to-visit.com -> redirect1.com -> final-domain.com
This code below works for a single redirect:
cy.origin('redirect1.com') => {
cy.visit('domain-to-visit.com');
});
But I need to support more than one redirect.
My reflex is to want to wrap the above code in another cy.origin but that is not supported yet.
How can I visit domain-to-visit.com and allow it to redirect to multiple origins in Cypress?
Just write an origin command for any redirect URL you are interested in testing something on.
If you have
domain-to-visit.com -> redirect1.com -> final-domain.comand want to take action infinal-domain.com, your code would beTesting the intermediate page
If you want to also test something on
redirect1.com, just add anothercy.origin(), not nested but sequentially.This only makes sense if the web page needs an action to go to the final page, as far as I can see.
A reproducible example
base-page.html
Uses HTML redirect in
<meta>tagServed on port 3000:
redirect1.html
Uses javascript redirect on button click.
Served on port 5500:
Test