I have a sequence of a few tests on an application that I want to run. I want these tests to be able to run in a sequence or individually (which requires logging in).
Currently, if I was to run these tests in a sequence, it tries to log in before every test, but throws error because it cannot find the email/password field (since /login already has a user logged in, it redirects to /dashboard) which don't contain those fields. The first test case in the sequence logs into the application and then starts the next.
This is the login script:
class LoginPage {
visit() {
cy.visit('/login', {
failOnStatusCode: false
});
}
fillPlayerCredentials() {
cy.fixture('playerFixture').then((player) => {
cy.get('[data-testid=loginEmailField]').should('be.visible').type(player.email);
cy.get(':nth-child(2) > .MuiFormControl-root > .MuiInputBase-root > .MuiInputBase-input')
.should('be.visible')
.type(player.password);
});
}
login() {
cy.get('[data-testid=loginButton]').click();
}
}
When I run my second test, I want to check if localStorage
is already set or if sc-token
already has a value, and if so, it can just move on into the actual test case and skip logging in**