I am trying to add login flow to my cypress tests.
I want to get it running on my machine, in the following environment:
- both app and OAuth server are running in docker containers
- both containers have their ports mapped to localhost:
- app is available at baseUrl: 'https://localhost:8888'
- OAuth Server is available at 'http://localhost:9081'
As you can see, there are 2 origins on the localhost.
If I try the simple code:
cy.visit('/mysecuredpage'); // this redirects to http://localhost:9081
cy.contains('Please log in');
cy.get('input#username').type('user1');
cy.get('input#password').type('password1');
cy.get('button#password-submit').click();
I get an error about conflicting origins:
The command was expected to run against origin `http://localhost:9081` but the application is at origin `https://localhost:8888`.
I was trying to follow SSO login custom command
cy.visit('/mysecuredpage'); // this redirects to http://localhost:9081
cy.origin('http://localhost:9081', () => {
cy.contains('Please log in');
cy.get('input#username').type('user1');
cy.get('input#password').type('password1');
cy.get('button#password-submit').click();
});
Unfortunately, this fails with an error about wrong domain:
CypressError: `cy.origin()` requires the first argument to be a different domain than top. You passed `http://localhost:9081` to the origin command, while top is at `http://localhost:9081`.
Either the intended page was not visited prior to running the cy.origin block or the cy.origin block may not be needed at all.
Am I running against some known limitation or doing sth wrong? I am not even sure if multiple origins in the same domain is the root cause of the problem, or is it caused by some usage pattern of my app (all pages are private and redirect immediately to Oauth - there is no login button on the app side)
Cypress: 11.0.1
Browser: Chrome 107 (headless)
Node Version: v18.6.0