Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress e2e test dock closing on cy.visit()

I'm using Cypress for e2e tests in an angular web app. When cypress first opens it goes to http://localhost:54401/__/#tests/integration/login.spec.ts

This shows the cypress test dock on the left side of the screen and the web output to the right. As soon as my beforeEach function calls cy.visit(), instead of changing the output, the main url at the top of the screen changes to: http://localhost:4200/__/#tests/integration/login.spec.ts

Angular then takes over, it can't find the __ route, so instead the page is redirected to my default page, and I lose the Cypress dock/test runner.

Cypress should just be changing the frame where my application is loaded, not the page url. Something is happening that is causing Cypress to manipulate the main browser url instead of the frame url.

enter image description here

How can this be fixed so that cypress targets the frame and not the main browser window? This has worked in the past and just recently started not working. I'm not sure if it's a cypress or chrome issue. I thought this may be an issue with cypress web security so I did try setting chromeWebSecurity: false in cypress.json to no avail. https://docs.cypress.io/guides/guides/web-security.html#Disabling-Web-Security

I'm using cypress 3.1.5.

like image 962
Ryan Langton Avatar asked Nov 07 '22 20:11

Ryan Langton


1 Answers

Filed a bug with the Cypress github project and was informed this usually occurs when an application has framebusting code. Turns out we were importing hammerjs. When I removed that import (in polyfills.js), it works fine.

import 'hammerjs';

For reference, the issue link is Entire test runner redirects to app's login page #3517

like image 157
Ryan Langton Avatar answered Nov 15 '22 06:11

Ryan Langton