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.
Disable Concurrency
Concurrent test execution is not suitable for tests that can only run in a certain order. To ignore the global concurrency setting for a particular fixture, use the disableConcurrency fixture method.
fixture`Fixture.disableConcurrency`
.page`https://devexpress.github.io/testcafe/example/`
.disableConcurrency;
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. Idle browser instances remain open. For example, if you specify the
--concurrency 3
CLI flag for a fixture with 2 tests, TestCafe launches three browsers. Two browser instances run two tests. The third instance remains open 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 take place after the final test in that fixture (or run) ends.
When you run TestCafe in concurrency mode, the framework does not wait for every after
hook to end before it starts the next fixture. Each browser starts the next fixture when it’s ready.
Use Concurrency on Remote Devices
If you run tests on remote devices, multiply the number of remote browsers you want to open by your concurrency factor. For example, if you want to run tests in Safari and Firefox, and your concurrency factor is 2
, you’ll need four remote browsers to run the tests:
testcafe -c 2 remote:4 tests/test.js
If you run your test against multiple remote browsers, open all instances of one browser before you connect the next browser.