Browsers

Browser support

TestCafe supports a wide array of modern browsers. The latest versions of the following browsers work without any extra configuration:

Browser Browser Alias
Chromium chromium
Google Chrome chrome
Google Chrome Canary chrome-canary
Microsoft Edge (Chromium-based only) edge
Mozilla Firefox firefox
Opera opera
Safari safari

Important

TestCafe 3.0 discontinued official support for Internet Explorer 11, several months after the browser’s official retirement. TestCafe 3.0 does not support legacy versions of Microsoft Edge.

TestCafe also supports:

Specify target browsers

CLI

Specify the browser alias as the first command line argument.

testcafe chrome my-fixture.js

The command above launches tests in Google Chrome. If you want to launch tests in multiple browsers, separate the aliases with a comma:

testcafe chrome,edge my-fixture.js

Use the all alias to launch the test in all your local browsers.

Test Runner API

Use the runner.browsers method to select the target browser:

await runner
    .browsers('chrome')
    .src('./tests/')
    .run();

Pass an array of browser aliases to select multiple browsers:

await runner
    .browsers(['safari', 'chrome'])
    .src('./tests/')
    .run();

Use the all alias to launch the test in all your local browsers.

Local browsers

TestCafe automatically detects local browsers. Run the following shell command to display a list of local browsers that work with TestCafe out of the box:

testcafe --list-browsers

Switch between Chrome channels

The chrome alias targets the stable channel of Google Chrome. To run tests in Chrome Beta or Chrome Dev, specify the path to the browser executable instead of the alias.

Switch between versions of Microsoft Edge

Important

TestCafe 3.0 does not support legacy versions of Microsoft Edge

Windows users can run tests in either the legacy or the Chromium version of Microsoft Edge. Open Windows Settings, navigate to Default Apps and select Default Apps by Protocol. Set the MICROSOFT-EDGE: protocol to whichever version of Edge you prefer. That version will open when you use the edge alias.

Custom browsers

To run tests in a browser that TestCafe can’t automatically detect, such as a portable browser, specify the path to the browser’s executable. Use the path: prefix:

testcafe path:d:\firefoxportable\firefoxportable.exe ./tests/
await runner
    .browsers('path:d:\firefoxportable\firefoxportable.exe')
    .src('./tests/')
    .run();

Alternatively, specify target browsers in your configuration file:

{
    "browsers": "path:`C:\\Program Files\\Google Chrome\\chrome.exe`"
}

Mobile Browsers, Cloud Browsers and Emulation

TestCafe makes it easy to maintain your website’s compatibility with a wide array of devices.

  • You can run TestCafe tests on remote devices such as smartphones and tablets.
  • You can run TestCafe tests on popular cloud testing services.
  • You can simulate mobile devices in Chromium-based browsers.

Read the Mobile Devices, Cloud Browsers and Emulation Guide for more information.

Note

Disable native automation to launch tests in mobile browsers, cloud browsers, and remote browsers.

Test in Headless Mode

Chrome and Firefox include headless mode — a less resource-intensive way to run TestCafe. Headless browsers don’t display their GUI, making it possible to run them without a GPU. Even then, you can still take screenshots and resize the browser window in headless mode.

Important

You cannot enable the userProfile option in a headless browser.

Add :headless to browser alias to launch a browser in headless mode.

testcafe "chrome:headless" tests/sample-fixture.js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:headless')
    .run();

To launch a custom headless browser, replace the path: prefix with that browser’s alias:

testcafe "firefox:d:\firefoxportable\firefoxportable.exe:headless" tests/sample-fixture.js
runner
    .src('tests/sample-fixture.js')
    .browsers('firefox:d:\firefoxportable\firefoxportable.exe:headless')
    .run();

User profiles: Enable extensions and custom settings

Important

You cannot enable the userProfile option in a headless browser.

Extensions and custom browser settings may interfere with your tests. That’s why TestCafe launches browsers with an empty user profile. If you wish to use your browser’s default user profile, enable the :userProfile option.

Warning

The :userProfile option is incompatible with the :headless option, emulation mode, and native automation.

testcafe firefox:userProfile tests/test.js
runner
    .src('tests/fixture1.js')
    .browsers('firefox:userProfile')
    .run();

To launch a custom browser with this option, replace the path: prefix with the browser alias:

testcafe chrome:d:\chrome_portable\chrome.exe:userProfile tests/test.js

Automation Port

TestCafe communicates with Chrome and Firefox though a remote control port. Usually, the framework scans for an available port, and assigns one automatically. You can specify a specific custom port with the cdpPort option (for Chrome) or the marionettePort option (for Firefox).

Chrome

testcafe "chrome:headless:cdpPort=9223" tests/sample-fixture.js
runner
    .src('tests/sample-fixture.js')
    .browsers('chrome:headless:cdpPort=9223')
    .run();

Firefox

testcafe "firefox:headless:marionettePort=9223" tests/sample-fixture.js
runner
    .src('tests/sample-fixture.js')
    .browsers('firefox:headless:marionettePort=9223')
    .run();