0

I tried to set the session as in a custom command and called it in beforeall block

Cypress.Commands.add('cLogin', (win: any) => {
    cy.request({
            method: 'POST',
            url: `loginAPIURL`,
            body: {
              UserName: userName,
              Password: password,
            },
          })
          .then((response) => {
            sessionStorage.setItem('TestApp', response.body);
            const token = sessionStorage.getItem('ChartsApp');        
            headers.token = response.body;
            headers.ChartsApp = response.body;
          })
    });

I called it in

describe('testing', () => { 
before('login is called', function () {
    cy.cLogin(); 
    // this is setting session and able to print here 
    });
});

Then I tried to get the session from the Test case via custom command as

Cypress.Commands.add('cLogOut', () => {
    const token = win.sessionStorage.getItem('TestApp');
   console.log(token);
}

this log is printing as null but not the value from above stored in the session

  it('testing session get', ()=> {
    cy.cLogOut(); // when this is called inside this custom command session data is null

   });

please help me solve this problem if anyone knows about it

ksk
  • 165
  • 14

0 Answers0