the app that I test has SSO login. So, 1st I am cy.vist(xxx) to one URL then system directs me another cy.visit(yyy). But currently I cant handle the issue that currently I am facing. Can you please help me to figure out?
Thank you
it.only("logs in using env variables", () => {
const username = Cypress.env("username");
const password = Cypress.env("password");
let href;
cy.visit("/");
cy.get(".chakra-stack > .css-1n94901").click()
cy.contains("Login with Carmarket").click();
cy.get(":nth-child(1) > .form-control").type(username);
cy.get(":nth-child(2) > .form-control").type(password);
cy.get(".login > .submit > .button").click({multiple: true,force: true});
cy.url().then((url) => {
href = url;
cy.log("href ", href);
cy.visit(href);
cy.url().should("include", "blabla[][1]][1]"); //assertion of that we are in this url
});
});
});
After clicking the login button, you can directly assert whether url contains some text. Also you can add some timeout as well for the redirection to complete.
cy.url({timeout: 6000}).should("include", "blabla[][1]][1]")
Considering your url is https://example.com/ Within the same test you can work with urls if they have format like https://example.com/something or https://example.com/something/123 or https://superdomain.example.com/. So basically the url should have the same origin. But in case the url is not from the same origin which is in your case, then you have to move to a new test to resolve this. This is a trade-off of cypress and you can read more about it from here. So you can do something like this:
it('logs in using env variables', () => {
const username = Cypress.env('username')
const password = Cypress.env('password')
let href
cy.visit('/')
cy.get('.chakra-stack > .css-1n94901').click()
cy.contains('Login with Carmarket').click()
cy.get(':nth-child(1) > .form-control').type(username)
cy.get(':nth-child(2) > .form-control').type(password)
cy.get('.login > .submit > .button').click({multiple: true, force: true})
})
it('validate content of url', () => {
cy.url({timeout: 6000}).should('include', 'blabla[][1]][1]')
})