createTestCafe Factory

Creates a TestCafe server instance.

async createTestCafe([hostname], [port1], [port2], [sslOptions], [developmentMode]) → Promise<TestCafe>
Parameter Type Description Default
hostname (optional) String The hostname or IP on which the TestCafe server is running. 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 Node.js documentation. See Connect to the TestCafe Server over HTTPS 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

Related configuration file properties:


Create a TestCafe instance with the createTestCafe function.

const createTestCafe = require('testcafe');

createTestCafe('localhost', 1337, 1338)
    .then(testcafe => {
        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');
let runner                  = null;

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

createTestCafe('localhost', 1337, 1338, sslOptions)
    .then(testcafe => {
        runner = testcafe.createRunner();
    .then(() => {
        return 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')

See Also