createTestCafe Function

Creates a TestCafe server instance.

async createTestCafe(options) → Promise<TestCafe>
Parameter Type Description
options (optional) Object See options.


Create a TestCafe instance with the createTestCafe function.

const createTestCafe = require('testcafe');
const options        = {
     hostname: 'localhost',
     port1:    1337,
     port2:    1338

const testCafeOptions = await createTestCafe(options);
const runner          = testcafe.createRunner();
/* ... */

Establish an HTTPS connection with the TestCafe server. The openssl-self-signed-certificate module is used to generate a self-signed certificate for development use.

'use strict';

const createTestCafe        = require('testcafe');
const selfSignedSertificate = require('openssl-self-signed-certificate');

const sslOptions = {
    key:  selfSignedSertificate.key,
    cert: selfSignedSertificate.cert

const testCafeOptions = {
    hostname: 'localhost',
    port1:   1337,
    port2:   1338,

const testcafe = await createTestCafe(testCafeOptions);
const runner   = testcafe.createRunner();

await runner

    // Browsers restrict self-signed certificate usage unless you
    // explicitly set a flag specific to each browser.
    // For Chrome, this is '--allow-insecure-localhost'.
    .browsers('chrome --allow-insecure-localhost')

await testcafe.close();


Type: Object

Parameter Type Description Default
hostname (optional) String The hostname or IP on which the TestCafe server runs. Must resolve to the current machine. To test on external devices, use the hostname that is visible in the network shared with these devices. Hostname of the OS. If the hostname does not resolve to the current machine - its network IP address.
port1, port2 (optional) Number Ports that will be used to serve tested webpages. Free ports selected automatically.
sslOptions (optional) Object Options that allow you to establish an HTTPS connection between the TestCafe server and the client browser. This object should contain options required to initialize a Node.js HTTPS server. The most commonly used SSL options are described in the TLS topic in the Node.js documentation. See Test HTTPS and HTTP/2 Websites for more information.
developmentMode (optional) Boolean Enables/disables mechanisms to log and diagnose errors. You should enable this option before you contact TestCafe Support to report an issue. false
cache (optional) Boolean If enabled, the TestCafe proxy caches webpage assets (such as stylesheets, images and scripts) for the webpages that it processes. The next time the proxy accesses the page, it loads assets from its cache instead of requesting them from the server. false
retryTestPages (optional) Boolean Retry failed network requests for webpages visited during tests. Requires a secure connection. false
configFile (optional) String Path to the Testcafe configuration file. null

Related configuration file properties:

See Also