简体   繁体   中英

Need to visit a registration link multiple times in Cypress

I have a bunch of Cypress tests that are being driven by a fixture file which contains the number of tests I want to run.

As part of my tests. I need to visit a registration link and register a new account.

The problem is that the first time I visit the registration form. It appears fine. But if I go to it again. The new form doesn't show and I only see the regular login form.

I suspect that because I'm running multiple tests from one spec file that Cypress is remembering that I've already visited the page and showing me the log in form.

I know I shouldn't be using the UI to register new accounts. But it's the only solution currently.

/// <reference types="cypress" />
let user;

before(function () {
    cy.task("newUser").then((user) => {
        user = user;
    });
});

const types = require("../fixtures/types");

types.forEach((type) => {
    context("Matter Creation", () => {
        it("Tests if a Service Agent can create a new matter", () => {
            cy.fixture("data").then((data) => {
                cy.addNewUser({
                    userEmail: user.email,
                    userPassword: user.password,
                });
            });
        });
    });

    context("User Registration", () => {
        it("Tests the registration process from a users perspective", () => {
            cy.userRegistration({
                userEmail: user.email,
                userPassword: user.password,
            });
        });

        it("Tests that users are registered and can sign in", () => {
            cy.verifyRegistration({
                userEmail: user.email,
                userPassword: user.password,
            });
        });
    });
});

Fixed it by moving my before state into my describe block.

It was reusing old data, instead of using new data for every test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM