https://cypress.io logo
Hi Cypress lovers! 👋 In last days I'm struggling ...
# e2e-testing
s
Hi Cypress lovers! 👋 In last days I'm struggling with login flow for E2E tests. I really wanted to use session and origin functionality, which was introduced in Cypress 9.6.0 for this use case. The problem looks like a standard one - login form is available in another domain and Cypress ofc can't make cross origin requests. I read in documentation (https://docs.cypress.io/api/commands/origin#SSO-login-custom-command) that this can be easily handled by
cy.origin()
but I tried to use that scheme and I couldn't managed it to work. 😦 The problem is that firstly I need to visit my application URL (baseURL) to be redirected to another domain. This step is necessary, as if the user has no valid session, it is directly redirected to the login form on another domain with additional information in a link, such as origin application and state for further token challenge (generated before redirecting and saved in session). After user submits the login form it is automatically redirected back to the page. So let's say we have something like this:
Copy code
js
cy.visit('/');
cy.origin('https://amazinglogin.test', () => {
  // Filling up the form and clicking submit
})
This isn't working in that case, as page never return load event (because it is programmatically moved to another domain) and test fails stuck on loaded page with form. In all examples that I saw Cypress always was loading a page, and then clicking a
magic
"login" button, which redirected to another domain - this would work fine. Do you know if there is some workaround for that or maybe this is a Cypress limitation for this moment? In worst case I will try to change login flow to using
cy.request()
to get token for the tests, but I will really like to avoid that, as this will increase complexity of the whole flow. And if you read this far, I hope you have a great day/evening! 😊
2 Views