Search code examples
automated-testscypresstest-data

Cypress test data generation scripts not as part of the test suites


I wrote a couple of Cypress end-2-end tests for our website. These tests run against a staging environment. Since we have a couple of those staging environments for our dev teams I would like to make sure these tests are stable on all stagings.

For some tests I need certain test data, so I wrote a cypress test, creating that test data. Normally this test data generation test is not executed on our CI system. This test is located in a separate file within the integration directory, so that cypress is able to find and execute it. It is just executed once per staging environment. The test data will just remain there and does not have to be generated again and again.

When opening the cypress GUI (cypress open) I would like to have this test data generation test being ignored by cypress so that I can simply run all suites at once. But, when I add this test data generation test to the set of ignoredTestFiles, I can't run the test data generation test at all anymore.

Do you have an idea how I can make the cypress GUI ignore my test data generation test on the one side and on the other keep it executable by cypress, when I explicitly want it to execute?


Solution

  • You could make the test generation data test depend on an environment variable, and only set that variable when you explicitly want it to execute. Something like:

    if (Cypress.env('GENERATE_TEST_DATA')) {
      // Generate your test data here
      // You could even put this if around the entire it block
      // so the test doesn't execute at all when the environment variable isn't set
    }
    

    Then when you want the test data to be generated, set the environment variable like this:

    CYPRESS_GENERATE_TEST_DATA=true npx cypress run
    

    Also see the documentation on Cypress.env()