HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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 :).');
            }
        })
    });
});