1

I'm trying to run tests for multiple sites by using different environments. The sites all follow the same template, so a generic test is enough to cover them all.

In my acceptance.suite.yml file I set up all the environments with the different urls.

In my Cest file, I have a load of functions that are called in a specific environment, and set up some variables that may differ between sites, log in info, etc.

I then call the same function for every environment.

When I'm running the acceptance tests I tell it which environments to run using multiple '--env foo'.

This all works, but I have over 20 sites to test, which means writing 20 '--env foo' every time I want to run a test. Seems a bit much.

Is there a better way?

1 Answer 1

1

If you have installed codeception using composer, you can edit the following file:

vendor/codeception/codeception/src/Codeception/Codecept.php

Navigate to the run function (Around line 125), and change the following:

    if (!$selectedEnvironments or empty($environments)) {
        $this->runSuite($settings, $suite, $test);
        return;
    }

    foreach ($environments as $env => $config) {
        if (!in_array($env, $selectedEnvironments)) {
            continue;
      }

Into:

    if (/*!$selectedEnvironments or*/empty($environments)) {
        $this->runSuite($settings, $suite, $test);
        return;
    }

    foreach ($environments as $env => $config) {
        /*if (!in_array($env, $selectedEnvironments)) {
            continue;
        }*/

Now it should run all environments by running "codecept run". You can modify the function as per your requirements, to for example only use a specific environment if specified, or else run all environments.

Actually if you change the last bit to the following, it will use the specified environments if set using --env, and else execute all:

 foreach ($environments as $env => $config) {
        if ($selectedEnvironments) {
            if (!in_array($env, $selectedEnvironments)) {
                continue;
            }
        }

If anybody knows how to cleanly rewrite a core function in Codecept.php without editing the file directly, I would love to hear because that would of course be a cleaner solution :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.