{ cy.session([username1, password1, Trac" /> { cy.session([username1, password1, Trac" /> { cy.session([username1, password1, Trac"/>

cy.session() with cy.request() does not log in user

165 views Asked by At
  1. 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.

  1. I call in my test
cy.loginByApi1(Cypress.env('mainInvestorUserEmail'), Cypress.env('mainInvestorUserPassword'), 'Cypress.env('trackingID')')
  1. This is the session body (passes successfully it seems - see image) Notice that cy.log(body.token) is empty

See Image

  1. When I try cy.visit('/') in order to visit my base page, URL is still redirected to login screen

  2. In my local storage i have these keys

(See second image)

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.

0

There are 0 answers