Home > other >  Calling Cypress tests from another Cypress test file
Calling Cypress tests from another Cypress test file

Time:01-14

I am writing some Cypress test to test an account deletion feature. Since the test is going to be deleting an account every time it runs I first want to create an account. I already have a test file for creating an account.

describe("Create Email User", () => {
    beforeEach(() => {
        cy.restoreLocalStorage();
    });

    afterEach(() => {
        cy.saveLocalStorage();
    });

    it("Clicks to Create New User", () => {
        cy.visit("/signin");
        cy.get('[data-cy="login-main-sign-up-link"]').click();
        cy.get('[data-cy="sign-in-content-top-header-text"]').should(
            "contain",
            "Create your account"
        );
    });

    it("Enters Form Data", () => {
        cy.get('[data-cy="sign-up-name-first-name-input"]').type("John");
        cy.get('[data-cy="sign-up-name-last-name-input"]').type("Smith");
        const newEmail = createEmail();
        cy.get('[data-cy="sign-up-name-email-input"]').type(newEmail);
        cy.get('[data-cy="sign-up-name-password-input"]').type("test123!");
        cy.get('[data-cy="sign-up-name-next-button"]').click();
        cy.get('[data-cy="sign-up-phone-header-text"]').should(
            "contain",
            "What's your phone number?"
        );
    });

    it("Reloads the page and clicks next button", () => {
        cy.reload();
        cy.get('[data-cy="sign-up-onboarding-intro-header-text"]').should(
            "contain",
            "Great! Let's set up your account"
        );
        cy.get('[data-cy="sign-up-onboarding-next-button"]').click();
        cy.get('[data-cy="sign-up-role-wizard-header-text"]').should(
            "contain",
            "What role best describes you?"
        );
    });

    it("Selects Family/Friend role and clicks next button", () => {
        cy.get('[data-cy="sign-up-role-wizard-Family/Friend"]').click();
        cy.get('[data-cy="sign-up-role-wizard-next-buton"]').click();
        cy.get('[data-cy="sign-up-base-header-text"]').should(
            "contain",
            "Do you know which base your trainee is going to?"
        );
    });

    it("Selects No button and clicks next button", () => {
        cy.get('[data-cy="sign-up-base-no-button"]').click();
        cy.get('[data-cy="sign-up-base-next-button"]').click();
    });
});

Now I am working on the account delete tests. I want to first call the create account tests so that I am sure there is an account to delete.

How do I call a testing file to run from another test file?

CodePudding user response:

Try using custom commands in cypress so that the login functionality can be used in other tests also

Refer https://docs.cypress.io/api/cypress-api/custom-commands#Syntax

  •  Tags:  
  • Related