File: D:/HostingSpaces/SBogers10/shop.komma.nl/tests/Cypress/support/site_commands.js
import PagesInfo from "./pagesInfo";
const pagesInfo = new PagesInfo();
Cypress.Commands.add('site_login', (intended_url, username = 'customer@komma.pro', password = 'Customer123') => {
cy.log('Heading to the intended url if possible...');
cy.visit(intended_url).then(() => {
cy.url().then((url) => {
cy.log('Current url is: '+url+' '+window.location);
if(url.includes('login') || url.includes(pagesInfo.getByName('siteLogin').locations.nl)) {
cy.log('That was not possible. We need to login.');
cy.get('input[name=email]').type(username);
cy.get('input[name=password]').type(password);
cy.get('[type=submit]').click();
cy.log('Logged in. Heading to the intended url');
cy.visit(intended_url).then(() => {
cy.url().should('include', intended_url);
});
} else {
cy.log('Intended url was reached. Not logging in :).');
}
})
});
});