Implementation:DevExpress Testcafe BrowserProvider
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Provider_Pattern |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
Concrete tool for wrapping browser provider plugins with a unified API for browser lifecycle management, window manipulation, and screenshot handling.
Description
The BrowserProvider class wraps a BrowserProviderPluginHost and delegates all browser operations to it, but intercepts window management calls to add platform-specific behavior. It finds window descriptors via testcafe-browser-tools, calculates resize corrections on Windows to handle maximized/normal mode differences, enforces macOS screen size limits, and falls back to local browser tools when the plugin does not have custom implementations. It handles the decision logic for using default window actions versus plugin-specific ones.
Usage
BrowserProvider instances are created by the BrowserProviderPool when resolving browser aliases. They normalize the browser interface across all built-in (Chrome, Firefox, Edge) and third-party providers.
Code Reference
Source Location
- Repository: DevExpress_Testcafe
- File: src/browser/provider/index.ts
- Lines: 1-497
Signature
export default class BrowserProvider {
private plugin: any;
private initPromise: Promise<any>;
private isMultiBrowser: boolean;
private localBrowsersInfo: Dictionary<LocalBrowserInfo>;
public constructor (plugin: any);
public async init (): Promise<void>;
public async dispose (): Promise<void>;
public isLocalBrowser (browserId?: string): boolean;
public isHeadlessBrowser (browserId?: string): boolean;
public hasCustomActionForBrowser (browserId: string): Promise<boolean>;
public async openBrowser (
browserId: string,
pageUrl: string,
browserOption: unknown,
additionalOptions: OpenBrowserAdditionalOptions
): Promise<void>;
public async closeBrowser (
browserId: string,
data: BrowserClosingInfo
): Promise<void>;
public async resizeWindow (
browserId: string,
width: number,
height: number,
currentWidth: number,
currentHeight: number
): Promise<void>;
public async maximizeWindow (browserId: string): Promise<void>;
public async takeScreenshot (browserId: string, screenshotPath: string, pageWidth: number, pageHeight: number, fullPage: boolean): Promise<void>;
public async canResizeWindowToBoundsWithoutRecalculation (browserId: string): Promise<boolean>;
public async reportWarning (browserId: string, ...args: any[]): void;
}
Import
import BrowserProvider from './browser/provider';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| plugin | BrowserProviderPluginHost | Yes | The plugin host wrapping the actual provider implementation |
| browserId | string | Yes | Unique identifier for the browser instance |
| pageUrl | string | Yes | URL to open in the browser |
Outputs
| Name | Type | Description |
|---|---|---|
| openBrowser() | void | Launches the browser and navigates to the page URL |
| takeScreenshot() | void | Captures screenshot to the specified file path |
| resizeWindow() | void | Resizes the browser window with platform corrections |
Usage Examples
// Internal usage within TestCafe
import BrowserProvider from './browser/provider';
// 1. Create provider from plugin
const provider = new BrowserProvider(pluginHost);
await provider.init();
// 2. Open a browser
await provider.openBrowser(
'browser-1',
'http://localhost:1337/test-page',
{ headless: true },
{ disableMultipleWindows: false }
);
// 3. Take a screenshot
await provider.takeScreenshot('browser-1', '/tmp/screenshot.png', 1280, 720, false);
// 4. Resize the window
await provider.resizeWindow('browser-1', 1024, 768, 1280, 720);
// 5. Close the browser
await provider.closeBrowser('browser-1', { isRestarting: false });
await provider.dispose();