cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.43k stars 3.14k forks source link

Cypress run command does not support Auth0 #29716

Open LukaButikashvili opened 2 weeks ago

LukaButikashvili commented 2 weeks ago

Current behavior

Currently, we are using Auth0 for registration. The test case starts with visiting the website, and if the user is not logged in, the site redirects to the Auth0 page. Then, it should log in using a custom command. (get from the docs), but getting an error:

"CypressError: Timed out retrying after 15000ms: The command was expected to run against origin https://domain.com but the application is at origin https://domain.auth0.com."

beforeEach(() => {
    cy.visit('/')

    cy.getCookie('appSession').then((cookie) => {
      if (!cookie) {
        cy.loginToAuth0(
          Cypress.env('auth0_username'),
          Cypress.env('auth0_password')
        )
      }
    })
  })

loginToAuth0 command is:

e2e/support/auth0Authentication.ts

declare namespace Cypress {
  interface Chainable {
    loginToAuth0(username: string, password: string): void
  }
}

function loginViaAuth0Ui(username: string, password: string) {
  cy.origin(
    Cypress.env('auth0_domain'),
    { args: { username, password } },
    ({ username, password }) => {
      cy.get('input#username').type(username)
      cy.get('input#password').type(password, { log: false })
      cy.contains('button[data-action-button-primary=true]', 'ログイン').click()
    }
  )
}

Cypress.Commands.add('loginToAuth0', (username: string, password: string) => {
  loginViaAuth0Ui(username, password)
})

Note that this problem only exists in Cypress run, not in Cypress open, and it affects test cases run in that way.

Desired behavior

Using origin it should be worked when running

Test code to reproduce

run command yarn cypress: run

package.json "cypress:run": "cypress run --browser chrome"

Cypress Version

^13.6.6

Node version

^18.17.0

Operating System

macOS Ventura 13.0.1

Debug Logs

No response

Other

No response

jennifer-shehane commented 1 week ago

@LukaButikashvili Could you make sure to use the latest version of Cypress?