So my application uses Microsoft login and then redirects back to the application.
I am trying to execute two test case files(.js) one after the other. I am doing so by importing them into a spec file and running it. The first step in both files is to login and then perform some task. Each file has different user credentials to login to. The first file with the first user, logs in and executes cases, but when the second file needs a different user login with his credentials, an error is thrown. I am calling a common login function for both files and only modifying the "user" parameter.
Can someone help me with a solution?
I have mentioned the login function I have.
Cypress.Commands.add("login", (user) =>
{
cy.sqlServer(select USERID, password from table name where User=${user}).then(function (result) {
var userID = result[0]
var password = result[1]
const credentials = { userID, password }
cy.session([userID, password], () => {
cy.viewport('macbook-16')
cy.visit('https://websitename.com/')
cy.get('.login-btn').click()
//clicking accept cookie button
cy.get('#onetrust-accept-btn-handler').should('be.visible').click()
//clicking microsoft login button
cy.get('#microsoft-external-auth-button').should('be.visible').click()
//redirected to microsoft login
cy.origin('https://login.microsoftonline.com', { args: credentials }, ({ userID, password }) => {
//entering username
//clicking next
//entering password
//clicking 'login' button
cy.wait(1000) }) }) })})