Native Automation Mode
TestCafe uses a reverse proxy to execute tests across different browsers, but this technique complicates the framework.
Since the original release of TestCafe, a number of native browser automation protocols became widely used. These protocols offer superior automation speeds and greater stability. That’s why the TestCafe team decided to gradually phase the reverse proxy out in favor of native support for these automation protocols.
If you use TestCafe v2.5.0 and up, you can automate Chromium-based browsers, such as Google Chrome and Microsoft Edge, with the native CDP protocol.
You can enable native automation mode from the command line interface, the Test Runner API, and the configuration file.
Migrating to Native Automation mode
The TestCafe proxy uses custom client-side automation scripts to emulate browser events. Native Automation mode, as the name suggests, uses the CDP protocol to natively fire browser events.
If you designed your tests for an earlier version of TestCafe, you may have inadvertently adjusted their code to accommodate the framework’s flawed event emulation. As a result, if you enable Native Automation, you may notice slight differences in your tests’ behavior. Tests that interact with custom elements, or perform calculations related to element state, may even fail.
If a test runs well without Native Automation, but fails when you enable the new mode, this behavior may not be a mistake. Check your code and make edits when appropriate.
Limitations
The TestCafe automation proxy was independent of browsers’ internal logic. This independence allowed TestCafe to grow its capabilities beyond what browsers can do “out of the box”.
Native automation limits the range of available browser interactions. As a result, the TestCafe team needs to come up with elaborate workarounds to keep all framework capabilities intact.
Below is the list of capabilities that do not currently work in Native Automation mode. Please be patient as the team works to resolve these issues.
- TestCafe cannot manage Multiple Browser Windows. Before you proceed, disable support for multiple windows.
- TestCafe cannot authenticate users with the NTLM protocol.
- When TestCafe interacts with the Shadow DOM, the mouse cursor is invisible.
- TestCafe cannot route HTTP requests through a proxy. Use the built-in capabilities of your operating system to configure a proxy connection.
- TestCafe cannot run tests in remote browsers, cloud browsers, and mobile browsers.
- Page events register when you enter debug mode.
- TestCafe hangs when it accesses
iframes
in local HTML files. - TestCafe cannot interact with
iframes
that thedocument.write
method injects into the page. - Users cannot disable page caching for tests and fixtures.
- TestCafe sets the value of the --hostname option to
localhost
, regardless of the user setting. - TestCafe ignores the page request timeout and the AJAX request timeout.
CLI
Include the --native-automation CLI flag when you launch TestCafe.
testcafe chrome tests --native-automation
Test Runner API
Set the nativeAutomation option to true
when you launch the TestCafe Test Runner.
const createTestCafe = require('testcafe');
const runner = createTestCafe();
runner.run({
nativeAutomation: true;
});
Configuration File
Set the nativeAutomation option to true
in the configuration file.
{
"nativeAutomation": "true"
}