Documentation
REFERENCE
createTestCafe Function
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 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 |
Related configuration file properties:
Example
Create a TestCafe
instance with the createTestCafe
function.
const createTestCafe = require('testcafe');
const testcafe = await createTestCafe('localhost', 1337, 1338);
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 testcafe = await createTestCafe('localhost', 1337, 1338, sslOptions);
const runner = testcafe.createRunner();
await runner
.src('test.js')
// 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')
.run();
await testcafe.close();