Implementation:DevExpress Testcafe TestController TypeDefs
| Knowledge Sources | |
|---|---|
| Domains | Type_Definitions, Testing, Browser_Automation |
| Last Updated | 2026-02-12 12:00 GMT |
Overview
Concrete TypeScript type declarations for TestCafe's TestController interface (t), the central object through which all browser actions, assertions, and test control operations are invoked.
Description
This file declares supporting types (NativeDialogHistoryItem, BrowserConsoleMessages, Browser, WindowDescriptor, CDPSession) and the main TestController interface. TestController exposes: context properties (ctx, fixtureCtx, browser, customActions), user interaction methods (click, rightClick, doubleClick, hover, drag, typeText, selectText, pressKey, dispatchEvent), scrolling, navigation (navigateTo, wait), file upload, screenshots, window management (openWindow, closeWindow, switchToWindow), iframe switching, native dialog handling, assertions (expect), debugging, role switching (useRole), request hooks, cookie management, HTTP requests (request), and CDP access (getCurrentCDPSession). TestControllerPromise extends both TestController and Promise<T> enabling method chaining.
Usage
These type declarations provide full TypeScript IntelliSense for the t (test controller) object in TestCafe TypeScript test files.
Code Reference
Source Location
- Repository: DevExpress_Testcafe
- File: ts-defs-src/test-api/test-controller.d.ts
- Lines: 1-588
Signature
interface TestController {
// Context
ctx: { [key: string]: any };
fixtureCtx: { [key: string]: any };
browser: Browser;
customActions: CustomActions;
// User interaction
click(selector: string | Selector, options?: ClickActionOptions): TestControllerPromise;
rightClick(selector: string | Selector, options?: ClickActionOptions): TestControllerPromise;
doubleClick(selector: string | Selector, options?: ClickActionOptions): TestControllerPromise;
hover(selector: string | Selector, options?: MouseActionOptions): TestControllerPromise;
drag(selector: string | Selector, x: number, y: number, options?: MouseActionOptions): TestControllerPromise;
dragToElement(selector: string | Selector, target: string | Selector, options?: DragToElementOptions): TestControllerPromise;
typeText(selector: string | Selector, text: string, options?: TypeActionOptions): TestControllerPromise;
selectText(selector: string | Selector, startPos?: number, endPos?: number, options?: ActionOptions): TestControllerPromise;
pressKey(keys: string, options?: PressActionOptions): TestControllerPromise;
dispatchEvent(selector: string | Selector, eventName: string, options?: object): TestControllerPromise;
// Navigation
navigateTo(url: string): TestControllerPromise;
wait(timeout: number): TestControllerPromise;
// Screenshots
takeScreenshot(options?: TakeScreenshotOptions | string): TestControllerPromise;
takeElementScreenshot(selector: string | Selector, path?: string, options?: TakeElementScreenshotOptions): TestControllerPromise;
// Window management
resizeWindow(width: number, height: number): TestControllerPromise;
maximizeWindow(): TestControllerPromise;
openWindow(url: string): WindowDescriptorPromise;
closeWindow(windowDescriptor?: WindowDescriptor): TestControllerPromise;
switchToWindow(windowDescriptor: WindowDescriptor | ((w: WindowFilterData) => boolean)): TestControllerPromise;
// Assertions
expect<A>(actual: A | Promise<A>): Assertion<A>;
// Roles
useRole(role: Role): TestControllerPromise;
// Request hooks
addRequestHooks(...hooks: object[]): TestControllerPromise;
removeRequestHooks(...hooks: object[]): TestControllerPromise;
// Cookies
getCookies(urls?: string | string[], names?: string | string[]): TestControllerPromise;
setCookies(cookies: CookieOptions | CookieOptions[]): TestControllerPromise;
deleteCookies(cookies?: CookieOptions | CookieOptions[]): TestControllerPromise;
// HTTP requests
request: RequestAPI;
// Debug
debug(): TestControllerPromise;
setTestSpeed(speed: number): TestControllerPromise;
setPageLoadTimeout(duration: number): TestControllerPromise;
// CDP
getCurrentCDPSession(): CDPSessionPromise;
}
interface TestControllerPromise extends TestController, Promise<any> { }
Import
// Automatically available in TestCafe TypeScript test files
// No explicit import needed - TestController is a global type
import { TestController } from 'testcafe';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| t (test controller) | TestController | Yes | Provided as parameter to test function body |
| selector | string or Selector | Varies | Target element for actions |
| options | ActionOptions (various) | No | Action-specific options (timeout, speed, offset) |
Outputs
| Name | Type | Description |
|---|---|---|
| TestControllerPromise | TestController & Promise | Chainable promise enabling fluent API |
| expect() | Assertion<A> | Assertion chain for verifying conditions |
| request | RequestAPI | HTTP request API for server-side requests |
Usage Examples
import { Selector, Role } from 'testcafe';
fixture('TypeScript Test').page('https://example.com');
test('Full TestController usage', async (t: TestController) => {
// Click and type
await t
.click('#username')
.typeText('#username', 'user@example.com')
.typeText('#password', 'secret', { replace: true })
.click('#submit');
// Assertions
await t.expect(Selector('.welcome').textContent).contains('Welcome');
// Navigation and screenshots
await t
.navigateTo('/dashboard')
.takeScreenshot({ path: 'dashboard.png', fullPage: true });
// Window management
const newWindow = await t.openWindow('https://example.com/popup');
await t.switchToWindow(newWindow);
await t.closeWindow();
// Cookie management
await t.setCookies({ name: 'session', value: 'abc123' });
const cookies = await t.getCookies();
// Request hooks and HTTP requests
const response = await t.request('https://api.example.com/data');
});