Concurrent Test Execution
To save time spent on testing, TestCafe allows you to execute tests concurrently.
Normally, you run tests with a command similar to the following one.
testcafe chrome tests/test.js
When this command is executed, TestCafe invokes an instance of the specified browser and runs tests in it.
Concurrency is an optional mode that allows you to invoke multiple instances of the same browser. These instances constitute the pool of browsers against which tests run concurrently, i.e. each test runs in the first free instance.
Concurrent test execution is not supported in Microsoft Edge. This is because there is no known way to start Edge in a new window and make it open a particular URL.
The following command invokes three Chrome instances and runs tests concurrently.
testcafe -c 3 chrome tests/test.js
This is how the same thing can be done through the API.
var testRunPromise = runner .src('tests/test.js') .browsers('chrome') .concurrency(3) .run();
Note that you can also use concurrency when testing against multiple browsers.
testcafe -c 4 safari,firefox tests/test.js
In this case, tests are distributed across four Safari instances and the same tests are also run in four Firefox instances.
If an uncaught error or unhandled promise rejection occurs on the server during test execution, all tests running concurrently will fail.
When you run tests on remote devices,
create connections for each instance of each browser you test against. When using
the command line interface, specify this number after the
remote: keyword. In API, create
a browser connection for each instance.
On a remote device, invoke all the required instances manually. The total number of instances
should divide by the concurrency parameter
n. Otherwise, an exception will be 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 connecting the next browser.