My login functionality testing does this:
- Type username
- Type password
- click login button
- check for agreement page
My POM for login page:
class loginPage {
fillUsername(value) {
cy.get('[id=username]').clear().invoke('val', value);
return this;
}
fillPassword(value) {
cy.get('[id=password]').clear().invoke('val', value);
return this;
}
clickLogin() {
//cy.intercept('/portal/api/login').as('login')
cy.contains("Login / S'identifier").click();
}
checkForAgreementPage(){
const path ='/license-agreement'
cy.wait(500) // <- All the problem is here in this line
// If I comment this line cy.url() yields current page's url
cy.url().then(($url) => {
cy.log($url)
if ($url.includes(path)) {
//cy.log('Clicked')
cy.get('[type=button]').contains('Accept').click();
}
});
}
}
export default loginPage;
My custom function command.js:
Cypress.Commands.add('login', (username, password) => {
lp.fillUsername(username);
lp.fillPassword(password);
lp.clickLogin();
lp.checkForAgreementPage();
});
My spec file:
it('TC01 - Login with valid data as wholesaler', () => {
cy.login(id.username, id.password); // for valid data
cy.visit('/users');
cy.logout();
});
it('TC05 - Login with username but no password ', () => {
cy.login(id.username, id.password); // For invalid data
cy.expected('span', 'Invalid username or password');
});
How can i remove wait function from POM login page? and wait till url is changed?
Also, I've tried to intercept 'api/login' and waited for it to load, but then this will fail the other tests where I am testing failed login scenarios