createTestCafe Function
Creates a TestCafe server instance.
async createTestCafe(options) → Promise<TestCafe>
Parameter | Type | Description |
---|---|---|
|
| See options. |
Example
Create a TestCafe
instance with the createTestCafe
function.
const reporter = require('../../reporter');
const tests = [
'../../../../tests/documentation/getting-started/**/*',
'../../../../tests/documentation/reference/test-api/**/*',
'../../../../tests/documentation/guides/**/*',
'../../../../tests/templates/**/*',
];
(async () => {
const createTestCafe = require('testcafe');
const options = {
hostname: 'localhost',
port1: 1337,
port2: 1338,
};
const testcafe = await createTestCafe(options);
await testcafe
.createRunner()
.reporter(reporter)
.src(tests)
.browsers('chrome')
.run({ disableNativeAutomation: true });
await testcafe.close();
})();
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.
const reporter = require('../../reporter');
(async () => {
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,
sslOptions,
};
const testcafe = await createTestCafe(testCafeOptions);
await testcafe.createRunner()
.src('test.js')
.reporter(reporter)
// 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();
})();
options
Type: Object
Parameter | Type | Description | Default |
---|---|---|---|
| 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. |
| Number | Ports that will be used to serve tested webpages. | Free ports selected automatically. |
| 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. | |
| Boolean | Enables/disables mechanisms to log and diagnose errors. You should enable this option before you contact TestCafe Support to report an issue. |
|
| 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. |
|
| Boolean | Retry failed network requests for webpages visited during tests. Requires a secure connection. |
|
| String | Path to the Testcafe configuration file. |
|
| Boolean | Disables support for HTTP/2 requests. |
|
Related configuration file properties: