App Actions

Let's learn about app actions and use it to speed up the testing.

We'll cover the following...

Introduction

We have just written our first Custom Command that registers a new user for every test. Unfortunately, it’s incredibly slow.

Press + to interact
context("The custom command could be run before the test code", () => {
it("Should leverage the custom registration command", () => {
cy.signupV1().should(user => {
expect(user).to.have.property("username").and.not.to.be.empty;
expect(user).to.have.property("email").and.not.to.be.empty;
expect(user).to.have.property("password").and.not.to.be.empty;
});
cy.log("The user is now registered and authenticated");
cy.findByText("New Post").should("be.visible");
});
});
context("The custom command could be run before the test code with a test hook", () => {
beforeEach(() => {
cy.signupV1().should(user => {
expect(user).to.have.property("username").and.not.to.be.empty;
expect(user).to.have.property("email").and.not.to.be.empty;
expect(user).to.have.property("password").and.not.to.be.empty;
});
});
it("Should leverage the custom registration command with a test hook", () => {
cy.log("The user is now registered and authenticated");
cy.findByText("New Post").should("be.visible");
});
});
context("The custom command could be customized", () => {
it("Should leverage the custom registration command", () => {
const user = {
username: "CustomTester",
email: "specialtester@realworld.io",
password: "mysupersecretpassword"
};
cy.signupV1(user).should("deep.equal", user);
cy.log("The user is now registered and authenticated");
cy.findByText("New Post").should("be.visible");
});
});

How the duration could be improved? Let’s introduce the concept of App Actions. The same way we leveraged and talked about App Constants, App Actions are utilities exposed directly from the front-end ...