I want to visit two websites and share data that has a common domain. But when I visit the second website, it redirects to url page after a few clicks.

After the last click in the code, it redirects the user automatically to the URL page given in cy.visit().

I tried separating it blocks as well but did not work.

Anyone can help?

Here is my code:

issue occurs after this line in code.

cy.get('.swal-button').click();

Expected: What I want is to keep the website there so that I can perform my tasks/interactions but I am unable to because it takes it back to default page.

describe.only('', () => {
    let emailText;
    let formattedDueDate;
    it('', () => {
        const baseUrl1 = 'https://iot-portal.britex.pw';
        cy.visit(baseUrl1 + '/');
        cy.wait(4000);
        emailText = '[email protected]';
        cy.get('input.MuiInputBase-input[name="email"]').type(emailText);
        cy.get('input[name="password"]').type('12345678');
        cy.get('button.MuiButtonBase-root[type="submit"]').click();
        cy.wait(5000);
        cy.url().should('include', '/dashboards/subscriptions');
        cy.get('[href="/dashboards/billinghistory"] > .MuiListItemText-root > .MuiTypography-root').should('have.text', 'Billing').click();
        cy.wait(2000);
        const dueDateContainer = cy.get('.flex.flex-col');
        // Extract the text of the due date element
        dueDateContainer.find('.MuiTypography-body1.text-green-600.font-medium.text-sm')
        .invoke('text')
        .then((dueDateText) => {
            const dueDate = new Date(dueDateText);
            // Format the date to YYYY-MM-DD
            formattedDueDate = dueDate.toISOString().split('T')[0];
            cy.log("------Value Before visiting Admin side ------: " + formattedDueDate);
            cy.visit('https://admin.britex.pw/login').then(() => {
                cy.log('Admin Portal visited successfully');
                cy.log('Logging in as admin');
                cy.get('.form-control[placeholder="Admin Email"]').type('[email protected]');
                cy.get('.form-control[placeholder="Password"]').type('12345678');
                cy.get('.btn.loginbtn').click();
                cy.log('Admin logged in successfully');
                // Continue with the rest of the test
                cy.get('.custom-select[name="company"]').select('1');
                cy.wait(2000);
                cy.get('.swal-button').click();
            })
        })
    });
});

0

There are 0 answers