Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
In Cypress, how to setCookie before test?

How to resolve it?

Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

cy.visit()

The cy command you invoked inside the promise was:

cy.setCookie()

enter image description here

/// <reference types="cypress" />

import { internet, name } from "faker";
import "cypress-localstorage-commands";

const email = internet.exampleEmail();
const password = internet.password();
const first_name = name.firstName();
const last_name = name.lastName();

let user;

before(function registerUser() {
  cy.request("POST", "https://api.domain.io/api/users/", {
    first_name: first_name,
    last_name: last_name,
    email: email,
    password: password,
  })
    .its("body")
    .then((res) => {
      user = res;
    });
});


beforeEach(function setUser() {
  cy.visit("https://app.domain.io/projects/create", {
    onBeforeLoad: (win) => {
      cy.setCookie("token", user.token);
    },
  });
});

describe("JWT", () => {
  it("create project", () => {
    cy.get('[type="text"]').type("Autotest project");
    cy.get('[type="submit"]').click();
  });
});

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I managed to resolve it this way:

beforeEach(function setUser() {
  cy.setCookie("token", user.token);
  cy.visit("https://app.domain.io/projects/create");
});

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

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!