Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Breaks Due to Page Redirect #1697

Closed
OmriAharon opened this issue May 9, 2018 · 10 comments
Closed

Testing Breaks Due to Page Redirect #1697

OmriAharon opened this issue May 9, 2018 · 10 comments
Labels
type: duplicate This issue or pull request already exists

Comments

@OmriAharon
Copy link

Current behavior:

I must go through a login of a different app in order for my own app to be working, I can't mock that. So the first line I do is as described below - I use cy.visit(..) to go to that page an log in. However, often when it starts the test, instead of visiting that page and fill the form to login, the entire Chrome tab goes redirects there (rather than just the app on the righthand side panel) and the testing panels are gone as if I just opened a new tab in Chrome and went to that page. I have to kill the cypress process and restart it. That usually fixes it, if not I just restart it a couple more times.

Desired behavior:

Testing proceeds as normal.

Steps to reproduce:

Maybe try to visit a different domain?

cy.visit(`https://different.app.com/session?redirect=${encodeURIComponent(myAppUrl)}`);

Versions

Cypress: 2.1.0
OS: MacOS High Sierra 10.13.3
Browser: Chrome 66

@brian-mann
Copy link
Member

If I'm understanding your question properly - this is a commonly asked question that's been answered on other various issues with links to how to do this properly. The short answer is you don't cy.visit the other app - you programmatically interact with it with cy.request.

Here's some other answers.

Feel free to reopen this issue if you feel this is not adequate enough.

@brian-mann brian-mann added the type: duplicate This issue or pull request already exists label May 9, 2018
@OmriAharon
Copy link
Author

OmriAharon commented May 9, 2018

Thanks for the quick response!

I forgot to mention that the other page's login is rather intricate, using iframes and several redirects and as you suggested I initially tried to use the cy.request method and it didn't seem to work. Not sure if I can make it work using only programatic requests. Is there an alternative?
I think it will work eventually, was just wondering if there's a different way. In any case, I'll work harder on that cy.request.

@ricovitch
Copy link

ricovitch commented Jun 12, 2018

Hello,

We are actually evaluating which solution to use for end2end testing in our project.
Cypress seems great, it has a nice developer experience, and good documentation/examples/etc.

But we hit a wall with the login step of our backoffice application because of the iframe/multiple domains restrictions.
I know there are a lot of informations and even a sample on how to get this kind of scenario working, but as we are not the team developing the backend and the authentification services, this is just a show stopper for us...

That and a straight forward way of running multiple test suites in parallel without a docker master degree

Sorry i don't want to seem rude, but i'm actually sad that we can not go further with cypress, as i feel it has great potential. I just wanted to share that.

@lyonsbp
Copy link

lyonsbp commented Nov 7, 2018

@ricovitch which e2e solution did you end up going with?

@ricovitch
Copy link

@lyonsbp i still think cypress is a great solution, but we had to make a pragmatic choice and we went with testcafe.
I think my complaint about concurrency is no longer valid with the latests cypress releases. But we still had no solution for the multiple domain login flow.

@sajjadhossain
Copy link

This is a big blocker for me and my team. I am trying to work around it using cy.request but i am not able to follow redirects using the location property in my requests' response.

@LisaBurleson
Copy link

LisaBurleson commented May 22, 2019

I'm hitting a similar wall, my login has a window.confirm then does a redirect that has iframes. The test runner always show the view, "Whoops, there is no test to run." No matter what I do, I can't get beyond this barrier. If I hit the back button, the test re-runs and the same "...no test to run." screen.

I've tried:
https://docs.cypress.io/api/events/catalog-of-events.html#Window-Confirm
https://gitter.im/cypress-io/cypress/archives/2017/09/05
#621

I really like this tool and how intuitive and great feedback it has and stepping through the test steps showing the state of the UI with before/after...but I can't log into the app, I can't use this tool.

@ghost
Copy link

ghost commented Jun 26, 2019

@brian-mann i'm not sure why this is closed. this is a really big blocker for us as well and can't get passed this redirect bug. Already wrote a LOT of tests for Cypress and would hate to have to move to something else because of something so silly.

Usecase:
/page immediately redirects to /page/hi but there is no way to test that this redirect happens. Cypress throws a 404 for some reason when the browser clearly redirects for the end user.

   it('properly load menu url', () => {
   	// Page should probably redirect to a default landing if plugged in randomly.
   	cy.visit('/page')
   		.location('pathname', { timeout: 10000 })
   		.should('eq', '/page/hi');
   });

@jiimaho
Copy link

jiimaho commented Sep 4, 2019

Yeah i'm having a similar issue.

Doing the following steps:

  1. cy.visit('/our/app') // causes a redirect to otherdomain.com/login
  2. cy.location('href').should('contain', 'otherdomain.com/login)
  3. // ...enters username and login details on otherdomain.com/login...
  4. cy.get('button').click() # simulate user clicking login button
  5. // now we're supposed to be redirected back to /our/app

even if - let's say 3 - redirects would happen (don't ask me why, login process..), then I would expect another assert with cy.location('href) would do the trick for me. Especially if I pass a timout of let's say 15 seconds (ignoring the fact that that might itself be a bad thing to do for now).

@jennifer-shehane
Copy link
Member

@bgold0 @jiimaho Please open a new issue with a completely reproducible example (test code that we can run and demonstrate the problem). We can't run code that is cy.visit('/page') for example to debug your exact problem and work on a fix. So until we are provided with your usecase, we can't move forward.

@cypress-io cypress-io locked and limited conversation to collaborators Jan 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

8 participants