https://cypress.io logo
Hi all, I'm looking for a way to setup a test befo...
# best-practices
f
Hi all, I'm looking for a way to setup a test before executing its steps. I'd like to use something like 'beforeIt', but so far as I know there is only 'before' (used for whole describe) and 'beforeEach' (the same actions for all ITs). I have several tests that have basically the same setup except the URL they are visiting. Yes, I can have a separate function like 'testSetup(fixtures.url)' which could aggregate all the neccessary actions, and call it as the first step of each IT. But I'd rather not have such 'setup' step since it's considered only as a prerequisite for the actual test steps. I figured out, that I can pass variables to 'beforeEach' hook via the config options parameter. But then typescript is not happy with the arbitrarily named parameter, since the Cypress config does not recognize it. The execution is working but I'm not much happy with such a solution 🙂 Do you have some hints, how to solve this? Code example:
Copy code
describe("Suite", () => {
    beforeEach(() => {
        // cy.visit(Cypress.config("testUrl"));
        cy.log(Cypress.config("testUrl" /* Using parameter from extended config */)); //
    });

    it("TC01", { testUrl: "/url1.com" /* Extending Cypress config with 'testUrl' parameter */ }, () => {
        cy.log("Running 1st test");
    });
    it("TC02", { testUrl: "/url2.com" /* Extending Cypress config with 'testUrl' parameter */ }, () => {
        cy.log("Running 2nd test");
    });
    it("TC03", { testUrl: "/url3.com" /* Extending Cypress config with 'testUrl' parameter */ }, () => {
        cy.log("Running 3rd test");
    });
});