I have a custom cypress command which performs some asynchronous tasks, and based on the result of the command I want to perform some assertions
But the problem is the tests that come after calling the command will either run before the command finishes or will have wrong values.
below is my code
Command
Cypress.Commands.add("testCommand", () => {
cy.request("http://localhost:3000/testApi").then(({ body }) => {
cy.request(`http://localhost:3000/testApi${body.query}`).then(() => {
console.log("success");
});
});
});
test
describe("Summary Page", () => {
it("my demo test", () => {
console.log("before command runs");
cy.testCommand();
console.log("after command runs");
});
});
Actual result
before command runs
after command runs
success
Required result
before command runs
success
after command runs
as you can see the output after command runs
will run before the command finished
Is there any way to wait for the command to complete before moving forward with tests