github-action icon indicating copy to clipboard operation
github-action copied to clipboard

Custom auth0 login command fails in CI

Open bunge12 opened this issue 3 years ago • 1 comments

With the new release of v9.6.0 and the new cy.session and cy.origin, along with multiple guides (guide 1, guide 2), I tried updating our Cypress tests to run using the new functionality. While I was able to run the commands locally, they would always fail on GitHub Actions. From the videos and screenshots, it looks like whenever the login command would run and redirect to auth0, the app would crash. I thought the issue might be with the app itself, but the tests ran successfully on Circle CI.

Stack used:

  • Cypress 9.7.0
  • Node v14
  • Chrome (headed)
  • Ubuntu-20

The command in question:

Cypress.Commands.add('loginAsUser', (email, password) => {
	const args = { email, password };
	cy.session(args, () => {
		// visit homepage
		cy.visit('/');
		cy.get('button[data-cy=login]').click();
		// redirects to Auth0
		cy.origin('AUTH0_DOMAIN', { args }, (args) => {
			cy.get('#username').type(args.email);
			cy.get('#password').type(args.password);
			cy.get('button')
				.contains(/^Continue$/)
				.click();
		});
		// assert we've returned to the site
		cy.get('h6[data-testid=clock]').should('exist');
		cy.get('button[data-cy=logout-button]').should('exist');
	});
});

The output on Github Actions:

The command was expected to run against origin https://auth0.com but the application is at origin `chrome-error://chromewebdata`.

This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.

Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `Login Behaviour`
      at Object.eval [as setup] (http://localhost:5000/__cypress/tests?p=cypress/support/index.js:38433:8)

bunge12 avatar May 26 '22 23:05 bunge12

Hi @bunge12, have you solved this issue? If yes, could you please share the solution?

Artem-Bosenko-01 avatar Sep 20 '22 11:09 Artem-Bosenko-01

Hi @Artem-Bosenko-01, we opted to run Cypress on CircleCI and it runs without any issues using the command from above.

bunge12 avatar Sep 26 '22 13:09 bunge12

Closing, since a workaround was found.

MikeMcC399 avatar Nov 04 '23 07:11 MikeMcC399