Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:DevExpress Testcafe NativeAutomation Entry

From Leeroopedia
Revision as of 11:12, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/DevExpress_Testcafe_NativeAutomation_Entry.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 the NativeAutomationRequestPipeline (for intercepting and rewriting network requests) and SessionStorage (for persisting test-run context). Its start() method iterates all registered API subsystems, starts each one, and wires up context-storage synchronization listeners. Its dispose() method stops the pipeline and cleans up resources.
  • NativeAutomationMainWindow extends the base class with isMainWindow = true. After starting, it calls Target.setDiscoverTargets on the CDP client to monitor newly created browser tabs. When a new page target appears, it emits the NEW_WINDOW_OPENED_IN_NATIVE_AUTOMATION event. The getNewWindowIdInNativeAutomation() method awaits this promise to hand back the target ID of the child window.
  • NativeAutomationChildWindow is a simple subclass that passes isMainWindow = false to 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

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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment