Cypress Waitings and Execution Order
Explore how Cypress manages asynchronous UI testing by automatically waiting for commands and controlling execution order. Understand Cypress’s queuing system, command chaining, and Test Runner interactivity to write more readable and reliable end-to-end tests for complex user flows.
We'll cover the following...
We'll cover the following...
Cypress waitings and execution order
In the previous lesson, we wrote the following initial test:
it("The happy path should work", () => {
cy.visit("/register");
cy.get(".form-control").then($els => {
cy.get($els[0]).type("Tester");
cy.get($els[1]).type("user@realworld.io");
cy.get($els[2]).type("mysupersecretpassword");
cy.get("button").click();
cy.contains("No articles are here").should("be.visible");
});
});
Without noting it, we’ve leveraged some of Cypress’s interesting features.
Automatic waiting
Did you notice that the test seems to have a synchronous flow? Think about what happens between a command and the next one:
cy.visit("/register");
// what does "visit" mean? When is Cypress going to execute the next commands? Is JavaScript ready?
cy.get(".form-control").then($els => {
cy.get($els[0]).type("Tester");
// typing is an asynchronous task, when will the next task start?
cy.get($els[1]).type("user@realworld.io");
cy.get($els[2]).type("mysupersecretpassword");
cy.get("button").click();
// the web app makes an AJAX call, a lot of time passes before ...