- I set up (in my cypress commands):
Cypress.Commands.add("loginByApi1", (username1, password1, TrackingId1) => {
cy.session([username1, password1, TrackingId1], () => {
cy.request({
method: 'POST',
url: 'https://someWebPage/api/challenge/credentials',
body: {
email: username1,
password: password1,
TrackingId: TrackingId1
}
}).then(({body}) => {
window.localStorage.setItem('authToken', body.token)
cy.log(body.token)
})
})
This is the endpoint with parameters used for login.
- I call in my test
cy.loginByApi1(Cypress.env('mainInvestorUserEmail'), Cypress.env('mainInvestorUserPassword'), 'Cypress.env('trackingID')')
- This is the session body (passes successfully it seems - see image) Notice that
cy.log(body.token)
is empty
When I try
cy.visit('/')
in order to visit my base page, URL is still redirected to login screenIn my local storage i have these keys
I tried replacing authToken
with accessToken
, since this is shown in local storage, but same result.
Not sure if I'm doing it correctly here, but this is on the official cypress site and other sites as well.
I can login using UI so my credentials and approach in that regard are correct.