https://cypress.io logo
Cypress - E2E testing : How to login with two diff...
# i-need-help
q
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) }) }) })})
c
Which SQL server you are using??? Use beforeEach to call Login
q
I am using Microsoft SQL server mgmt studio and the login function is called in beforeEach itself. I have attached the error am getting

https://cdn.discordapp.com/attachments/1102836639715315762/1103196790385287198/error.png

And this is how I am executing the files. By just running the testCases.spec.js file.

https://cdn.discordapp.com/attachments/1102836639715315762/1103197957043539979/image.png

c
cy.origin(microsoftonline) cy.visit(use your Application URL) Is it resolved???
q
No its not. My login function already uses the same logic as you mentioned 😅
c
I have DM you the logic which I used for my scenario
please check once
b
Hey @quiet-dream-68129 can I mark this question resolved ? 😀
q
Hi @best-flower-17510 , the issue still remains unresolved 😕