testingparallel-processingtestcafee2e

Testcafe parallelization for test batches


I'd like to know if its possible to run parallely test cases for test batches. What I mean is the following:

My project structure has 2 folders Folder1 and Folder 2 .

Folder 1 has test1, test2, test3, test4

Folder 2 has test5, test6, test7

I've tried smth like thisnpx testcafe "chrome" --concurrency 2 .\e2e\regression\Folder1\** .\e2e\regression\Folder2\**

The problem of above mentioned approach is that instance 1 will run tests from folder1 and instance 2 will run again tests from folder1.

So I'd like to know if its possible to do somehow with concurrency flag set on (or any other recommended way) to make it work. I'd like to achieve that instance 1 runs folder 1 related tests at the same time while instance 2 runs folder 2 related test cases.


Solution

  • Use the runner instance to achieve this goal.

    const createTestCafe = require('testcafe');
    const tests = [
      './e2e/regression/Folder1/**',
      './e2e/regression/Folder2/**',
    ];
    
    (async () => {
      const testcafe = await createTestCafe();
      const runners  = [];
    
      tests.forEach(test => {
        runners.push(
          testcafe
            .createRunner()
            .src(test)
            .browsers('chrome')
            .run()
        )
      })
    
      await Promise.all(runners);
      await testcafe.close();
    })();