Run Tests Concurrently

TestCafe can execute tests concurrently to cut test suite execution time. In concurrent mode, TestCafe invokes multiple instances of each browser, and divides the test workload between these instances.

Enable Concurrency

CLI

The -c (--concurrency) command line option enables concurrent test execution.

The concurrency factor applies to each of the browsers in your browser list.

The following command invokes three Chrome instances and three Firefox instances (six browser instances in total):

testcafe chrome, firefox test.js  --concurrency 3

Runner

The runner.concurrency API method enables concurrent test execution.

The concurrency factor applies to each of the browsers in your browser list.

The following command invokes three Chrome instances and three Firefox instances (six browser instances in total):

var testRunPromise = runner
    .src('tests/test.js')
    .browsers('chrome, firefox')
    .concurrency(3)
    .run();

Configuration file

You can enable concurrent test execution with the concurrency configuration file property.

Limitations

  • Microsoft Edge Legacy does not support concurrent test execution.

  • TestCafe opens the specified number of browser instances regardless of the number of tests in the test suite. Empty browser instances that run no tests remain open. For example, if you specify the --concurrency 3 CLI flag for a fixture with 2 tests, two browser instances run two tests and keeps the third browser instance in standby mode.

  • If an uncaught error or unhandled promise rejection occurs during test execution, all concurrently running tests fail.

Concurrency and Hooks

TestCafe executes before fixture hooks and run hooks before the beginning of the first test. The after fixture and run hooks are executed after the final test in that fixture (or run) ends.

TestCafe does not start a new fixture until after it completes the last after hook.

Use Concurrency on Remote Devices

If you run tests on remote devices, create browser connections for each instance of each browser you test against. The total number of instances is c*n, where c is the concurrency factor and n is the number of browsers.

In the command line interface, specify the number of browser instances after the remote: keyword. For example, use -c 2 remote:6 to run tests in Chrome, Firefox, and Edge, with two instances of each browser. If you use the API, create a browser connection for each instance in code.

Launch all the required browser instances manually on a remote device. The total number of instances should be divisible by the concurrency factor c. Otherwise, an exception is thrown.

testcafe -c 2 remote:4 tests/test.js

If you test against multiple remote browsers, open and connect all instances of one browser before you connect the next browser.