Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with cypress redirect

Situation: I am writing test automation for a website. There comes a point where there is a link button on my website. Clicking this I am redirected to an external website. There I have to log in and as soon as I do that I am redirected to my original web-page which contains some 'connections' that I need.

Problem: As soon as cypress clicks on the redirection button it does into a blank page.

Ideal solution: I would want to automate the entire scenario. If not then at-least a work around.

like image 555
ITguy Avatar asked May 25 '18 13:05

ITguy


People also ask

Does Cypress Support cross origin?

With the experimental cy. origin() command, new in Cypress 9.6. 0, you can easily switch between origins to seamlessly test syndicated authentication, cross-site CMS workflows and much more.


1 Answers

As suggested in the Cypress Docs, you should really be using cy.request() to log in. You don't control a 3rd party site, and that makes your test very flakey. For example, a lot of login pages are constantly changing and are A/B tested for the purpose of preventing a bot from logging in, including testing bots. The data:, url is probably the result of a http redirect.

Thankfully, using cy.request() you can 'fake' logging in by making a request to the server through code (which doesn't change as much) and you will never have to leave your app to log in

Here's a recipe for Single Sign-On for example.

Hope that makes sense!

like image 76
bkucera Avatar answered Oct 13 '22 01:10

bkucera