• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

139
Views
setLocalStorage is not working on cypress test

I have a problem with token.

I have loginCommand.

Cypress.Commands.add('login', (user, password) => {
  cy.request('POST', `${Cypress.env('API')}/auth/login`, {
    email: Cypress.env(user),
    password: Cypress.env(password),
  })
    .its('body')
    .then(res => {
      cy.log('res:', res);
      cy.setLocalStorage('token', res.token);
    });
});

I am trying to add new offer. And this is the test case.

it('can create an projectOffer C232 C233 C234 C235 C236', () => {
  //cy.seed(token);
  cy.fixture('offerA').as('offerA');
  cy.login('testEmail', 'testPwd');
  cy.visit(base);
  const customerRef = `create offer test ${new Date().toISOString()}`;
  cy.fixture('offerA').then(offerA => {
    cy.createOffer(offerA, customerRef);
  });
});

and also this is the related part of my code.

Cypress.Commands.add('createOffer', (offer, offerName) => {
  cy.get('[data-testid=app-toolbar-item]').click();

The error is

[data-testid=app-toolbar-item], but never found it.

In the application tab I see that my token is not there

What can I do for fixing this?

about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error