Implementation:DevExpress Testcafe NativeAutomation Entry
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, CDP Integration |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
NativeAutomationBase, NativeAutomationMainWindow, and NativeAutomationChildWindow are the main entry point classes that bootstrap TestCafe's native automation subsystem, which drives browsers directly via the Chrome DevTools Protocol instead of through a proxy.
Description
The native automation entry module defines a three-class hierarchy for managing CDP-based browser automation sessions:
- NativeAutomationBase is an abstract base class extending
AsyncEventEmitter. It owns theNativeAutomationRequestPipeline(for intercepting and rewriting network requests) andSessionStorage(for persisting test-run context). Itsstart()method iterates all registered API subsystems, starts each one, and wires up context-storage synchronization listeners. Itsdispose()method stops the pipeline and cleans up resources.
- NativeAutomationMainWindow extends the base class with
isMainWindow = true. After starting, it callsTarget.setDiscoverTargetson the CDP client to monitor newly created browser tabs. When a new page target appears, it emits theNEW_WINDOW_OPENED_IN_NATIVE_AUTOMATIONevent. ThegetNewWindowIdInNativeAutomation()method awaits this promise to hand back the target ID of the child window.
- NativeAutomationChildWindow is a simple subclass that passes
isMainWindow = falseto the base constructor, inheriting all base behaviour without additional window-discovery logic.
Usage
Use NativeAutomationMainWindow when creating the initial browser connection for a test run under native automation mode. Use NativeAutomationChildWindow when a test opens a new window (e.g., via window.open) and the framework needs to attach a second CDP session to the new target.
Code Reference
Source Location
- Repository: DevExpress_Testcafe
- File: src/native-automation/index.ts
- Lines: 1-113
Signature
export class NativeAutomationBase extends AsyncEventEmitter {
protected readonly _client: ProtocolApi;
public readonly requestPipeline;
public readonly sessionStorage: SessionStorage;
private readonly options: NativeAutomationInitOptions;
protected readonly windowId: string;
public constructor (
browserId: string,
windowId: string,
client: ProtocolApi,
options: NativeAutomationInitOptions,
isMainWindow: boolean,
);
public async start (): Promise<void>;
public async dispose (): Promise<void>;
public get apiSystems (): NativeAutomationApiBase[];
}
export class NativeAutomationMainWindow extends NativeAutomationBase {
public constructor (
browserId: string,
windowId: string,
client: ProtocolApi,
options: NativeAutomationInitOptions,
);
async start (): Promise<void>;
public async getNewWindowIdInNativeAutomation (): Promise<string>;
}
export class NativeAutomationChildWindow extends NativeAutomationBase {
public constructor (
browserId: string,
windowId: string,
client: ProtocolApi,
options: NativeAutomationInitOptions,
);
}
Import
import {
NativeAutomationBase,
NativeAutomationMainWindow,
NativeAutomationChildWindow,
} from '../native-automation/index';
I/O Contract
Constructor Inputs (NativeAutomationBase)
| Parameter | Type | Description |
|---|---|---|
browserId |
string |
Unique identifier for the browser connection |
windowId |
string |
CDP target ID of the browser tab/window |
client |
ProtocolApi |
Chrome Remote Interface protocol client |
options |
NativeAutomationInitOptions |
Configuration for the native automation session |
isMainWindow |
boolean |
Whether this represents the primary browser window |
Key Method Outputs
| Method | Return Type | Description |
|---|---|---|
start() |
Promise<void> |
Initializes all API subsystems and event listeners |
dispose() |
Promise<void> |
Stops the request pipeline and releases resources |
getNewWindowIdInNativeAutomation() |
Promise<string> |
Returns the target ID of a newly opened child window (main window only) |
Usage Examples
// Creating a main-window native automation session
const mainAutomation = new NativeAutomationMainWindow(
browserId,
targetId,
cdpClient,
nativeAutomationOptions,
);
await mainAutomation.start();
// When a new window opens, get the child window ID
const childWindowId = await mainAutomation.getNewWindowIdInNativeAutomation();
// Create a child-window session for the new tab
const childAutomation = new NativeAutomationChildWindow(
browserId,
childWindowId,
childCdpClient,
nativeAutomationOptions,
);
await childAutomation.start();
// Cleanup
await childAutomation.dispose();
await mainAutomation.dispose();
Related Pages
- Environment:DevExpress_Testcafe_Node_Runtime
- DevExpress_Testcafe_NativeAutomation_Input - CDP input event dispatch used alongside native automation sessions
- DevExpress_Testcafe_NativeAutomation_ResourceInjector - Script injection into page responses via CDP
- DevExpress_Testcafe_NativeAutomation_CookieProvider - CDP-based cookie management for native automation
- DevExpress_Testcafe_NativeAutomation_RequestHookEventProvider - Request hook lifecycle within native automation