Speed Up Test Execution

Use one of the following strategies to decrease test execution time:

Run Tests Concurrently

Main article: Run Tests Concurrently.

Enable concurrency to run multiple tests simultaneously.

Set the concurrency property in the configuration file:

{
  "concurrency": 3
}

If you use the command line interface, enable the --concurrency option:

testcafe --concurrency 3 chrome tests/

Concurrent test runs yield lower test suite execution times, but require more system resources. Only increase the concurrency factor if your system has enough resources.

Run Tests in Headless Browsers

Main article: Test in Headless Mode

Headless browsers (browsers without a GUI) take less time to initialize. Additionally, they enable you to run tests in environments without graphical capabilities, such as containers.

Use Roles

Main article: Authentication and Roles

Roles are re-usable authentication routines. If you test resources that require authentication, User Roles can help you save time.

When you first enable a Role, TestCafe executes log-in actions and saves the user authentication data. During subsequent Role activations, TestCafe does not perform any actions — it just retrieves authentication data from storage.

Place Role statements inside before and beforeEach hooks. That way, TestCafe gathers Role authentication data at the very beginning of the test suite, and all subsequent activations happen instantaneously.

Note

Roles save authentication data from cookie storage, sessionStorage and localStorage. If your authentication system stores data elsewhere, roles may not work.

Reset Test Speed

The speed parameter controls action emulation speed.

The default value of speed is 1, the fastest possible emulation speed. Lower speed values increase test suite execution time, but may be useful for debugging purposes.

If you set a custom speed value earlier, disable this setting or set it to 1.

Run Tests in Local Browsers

Network latency negatively impacts test execution speed. Run your tests in local browsers for optimal performance.

Mock Time-Consuming Requests

Main article: Intercept HTTP Requests

Mock the responses of time-consuming HTTP requests to speed up the testing process.

The TestCafe request mocker can intercept your application’s requests to external resources, and respond to these requests with the data that you specify. A mocked request is resolved almost instantly, and eliminates possible delays caused by data processing and network latency.

Optimize Your Page Model

Main article: Page Model

The simultaneous use of multiple page model objects increases test execution time and memory consumption. Modify your page model file to ensure that you only use one page model object per test run. Create a PageModel class and export it:

PageModel.js

class PageModel {
    //page model contents
}
export default new PageModel()

test.js

import PageModel from 'path/to/page-model.js'

Enable Server-Side Caching

Note

The cache option doesn’t cache HTML content and assets heavier than 5 MB.

TestCafe can cache web assets, such as images, scripts, and videos, and retrieve them from cache when necessary. Use server-side caching to avoid duplicate network requests and decrease test suite execution time.

Use any of the following to enable server-side caching: