Runner.browsers Method

Configures the test runner to run tests in the specified browsers.

browsers(browser) → this

The browser parameter can be any of the following objects or an Array of them:

Parameter Type Description Browser Type
String | Array A different browser alias for each browser type. See Browser Support for more details. Local browsers, cloud browsers, and browsers accessed through browser provider plugins.
{path: String, cmd: String} The path to the browser's executable (path) and command line parameters (cmd). The cmd property is optional. Local and portable browsers
BrowserConnection The remote browser connection. Remote browsers

You do not need to call this function if you specify the browsers property in the configuration file.

Related configuration file property: browsers

Use Browser Aliases

You can identify locally installed browsers with predefined browser aliases:

runner.browsers(['safari', 'chrome']);

You can also use aliases to run browsers accessed with provider plugins, such as browsers in cloud testing services:

runner.browsers('saucelabs:Chrome@52.0:Windows 8.1');

Specify the Path to the Browser Executable

To specify the path to the browser executable, use the path: prefix. Enclose the path in backticks if it contains spaces:

runner.browsers('path:`C:\\Program Files\\Internet Explorer\\iexplore.exe`');

Specify the Path With Command Line Parameters

runner.browsers({
    path: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
    cmd: '--new-window'
});

Headless Mode, Device Emulation and User Profiles

You can add postfixes to browser aliases to run tests in the headless mode, use Chrome device emulation or user profiles:

runner.browsers('chrome:headless');

For portable browsers, use the browser alias followed by the path to an executable:

runner.browsers('firefox:/home/user/apps/firefox.app:userProfile');

The path: prefix does not support postfixes.

Pass a Remote Browser Connection

const createTestCafe = require('testcafe');
let runner           = null;
let testcafe         = null;

createTestCafe('localhost', 1337, 1338)
    .then(tc => {
        testcafe = tc;
        runner   = testcafe.createRunner();

        return testcafe.createBrowserConnection();
    })
    .then(remoteConnection => {

        // Outputs remoteConnection.url so that it can be visited from the remote browser.
        console.log(remoteConnection.url);

        remoteConnection.once('ready', () => {
            runner
                .src('test.js')
                .browsers(remoteConnection)
                .run()
                .then(failedCount => {
                    console.log(failedCount);
                    testcafe.close();
                 });
        });
    });