Implementation:Getgauge Taiko TypeScript Definitions
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, Type Safety |
| Last Updated | 2026-02-12 03:00 GMT |
Overview
TypeScript Definitions provides the complete set of TypeScript type declarations for Taiko's public API, enabling IDE autocompletion, compile-time type checking, and self-documenting function signatures for all 80+ exported functions and 30+ interfaces.
Description
The index.d.ts file (located at types/taiko/index.d.ts) is a TypeScript declaration file that describes the entire public surface area of the Taiko browser automation library. It requires a minimum TypeScript version of 3.5 and imports the devtools-protocol type package for the Protocol.Network.Cookie type alias. The file is referenced in the project's package.json via the "types": "./types/taiko/index.d.ts" field, which means TypeScript consumers automatically pick up these declarations when importing the taiko package.
The declaration file is organized into several logical sections. Options interfaces define the configuration shapes for browser operations: BrowserOptions (headless, args, host, port, observe), NavigationOptions (headers, waitForNavigation, navigationTimeout, waitForEvents), ClickOptions (button, clickCount, position), WriteOptions (delay, hideText), ScreenshotOptions (path, fullPage, encoding), ViewPortOptions, CookieOptions, LocationOptions, and GlobalConfigurationOptions. Element and Selector interfaces define the core abstractions for interacting with page elements: Element (with methods like text(), value(), isVisible(), getAttribute()), ElementWrapper (with exists(), get(), elements()), and specialized wrappers such as TextBoxWrapper, DropDownWrapper, CheckBoxWrapper, RadioButtonWrapper, and FileFieldWrapper. Intercept types describe the request interception API: InterceptRequest (with continue() and respond() methods, plus full request metadata), InterceptMockData, and interceptRequestHandler.
The function declarations cover every public Taiko API method grouped by category: browser actions (openBrowser, closeBrowser, switchTo, intercept, emulateNetwork, emulateDevice, setViewPort), page actions (goto, reload, click, doubleClick, write, press, scrollTo, screenshot, tap), selectors ($, image, link, button, textBox, dropDown, checkBox, radioButton, text), proximity selectors (toLeftOf, toRightOf, above, below, within, near), dialog handlers (alert, prompt, confirm, beforeunload), and helpers (evaluate, to, into, accept, dismiss, setConfig, getConfig, currentURL, waitFor). Each function declaration includes links to the corresponding official Taiko API documentation page as JSDoc comments.
Usage
These type definitions are used automatically by TypeScript projects that depend on the taiko npm package. When a developer writes import { openBrowser, goto, click } from 'taiko' in a .ts file, the TypeScript compiler resolves the types from this declaration file, providing full autocompletion and type checking. JavaScript developers also benefit through JSDoc-powered IntelliSense in editors like VS Code that read .d.ts files for autocompletion hints even in plain .js files. The declarations ensure that incorrect argument types, missing required parameters, or invalid option shapes are caught at development time rather than at runtime.
Code Reference
Source Location
- Repository: Getgauge_Taiko
- File: types/taiko/index.d.ts
- Lines: 1-804
Signature
Key option interfaces:
export interface BrowserOptions {
headless?: boolean;
args?: string[];
host?: string;
port?: number;
ignoreCertificateErrors?: boolean;
observe?: boolean;
observeTime?: number;
dumpio?: boolean;
}
export interface NavigationOptions extends BasicNavigationOptions, EventOptions {
headers?: object;
waitForStart?: number;
}
export interface ClickOptions extends NavigationOptions, ForceOption {
button?: "left" | "right" | "middle";
clickCount?: number;
position?: string;
elementsToMatch?: number;
}
Core element interfaces:
export interface Element {
objectId: string;
description?: string;
get(): string;
text(): Promise<string>;
value(): Promise<string>;
isVisible(): Promise<boolean>;
isDisabled(): Promise<boolean>;
getAttribute(value: string): Promise<string>;
// ... additional methods
}
export interface ElementWrapper {
get(retryInterval?: number, retryTimeout?: number): Promise<ElementWrapper>;
readonly description: string;
exists(retryInterval?: number, retryTimeout?: number): Promise<boolean>;
text(): Promise<string>;
isVisible(retryInterval?: number, retryTimeout?: number): Promise<boolean>;
elements(retryInterval?: number, retryTimeout?: number): Promise<Element[]>;
}
Primary function exports (selected):
export function openBrowser(options?: BrowserOptions): Promise<void>;
export function closeBrowser(): Promise<void>;
export function goto(url: string, options?: NavigationOptions): Promise<Response>;
export function click(selector: SearchElement | MouseCoordinates, options?: ClickOptions | RelativeSearchElement, ...args: RelativeSearchElement[]): Promise<void>;
export function write(text: string, into?: SearchElement, options?: WriteOptions): Promise<void>;
export function press(keys: string | string[], options?: KeyOptions): Promise<void>;
export function emulateDevice(deviceModel: string): Promise<void>;
export function screenshot(selector?: SearchElement, options?: ScreenshotOptions): Promise<Buffer | undefined>;
export function evaluate<T>(selector?: Selector | string | EvaluateHandler<T>, handlerCallback?: EvaluateHandler<T>, options?: EvaluateOptions): Promise<T>;
Import
// TypeScript import (types resolved automatically via package.json "types" field)
import { openBrowser, goto, click, write, closeBrowser } from 'taiko';
// Or import specific types
import type { BrowserOptions, NavigationOptions, ElementWrapper, InterceptRequest } from 'taiko';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | N/A | N/A | This is a type declaration file with no runtime code. It provides compile-time type information only. The TypeScript compiler reads it automatically when the taiko package is imported.
|
Outputs
| Name | Type | Description |
|---|---|---|
| Type declarations | TypeScript .d.ts |
80+ function signatures, 30+ interfaces/types, and type aliases consumed by the TypeScript compiler for type checking and IDE features. |
Key exported types summary:
| Category | Types / Interfaces | Count |
|---|---|---|
| Options | BrowserOptions, NavigationOptions, ClickOptions, WriteOptions, KeyOptions, TapOptions, ScrollOptions, ScreenshotOptions, ViewPortOptions, CookieOptions, CookieDetailOptions, LocationOptions, GlobalConfigurationOptions, EvaluateOptions, DollarOptions, TableCellOptions, MatchingOptions, OpenWindowOrTabOptions, ResizeWindowOptions, ReloadOptions, ForceOption, ForcedNavigationOptions |
22 |
| Elements & Selectors | Element, ElementWrapper, ValueWrapper, ButtonWrapper, DollarWrapper, ImageWrapper, LinkWrapper, ListItemWrapper, TableCellWrapper, TextWrapper, ColorWrapper, FileFieldWrapper, TextBoxWrapper, DropDownWrapper, TimeFieldWrapper, RangeWrapper, CheckBoxWrapper, RadioButtonWrapper, BasicSelector, MatchingNode, RelativeSearchElement, Selector, SearchElement |
23 |
| Intercept | InterceptRequest, InterceptMockData, InterceptRedirectUrl, interceptRequestHandler |
4 |
| Other | Cookie, BrowserEvent, Response, BasicResponse, AttrValuePairs, ViewPort, ViewPortScreenOrientation, DragAndDropDistance, MouseCoordinates, DialogValue, DialogHandler, EvaluateHandler, EvaluateHandlerArgs, ProximitySelectorNearOptions |
14 |
| Functions | openBrowser, closeBrowser, goto, click, write, press, emulateDevice, screenshot, evaluate, and 70+ more |
80+ |
Usage Examples
Type-Safe Browser Automation Script
import { openBrowser, goto, click, write, closeBrowser, into, textBox, button } from 'taiko';
import type { BrowserOptions, NavigationOptions } from 'taiko';
const browserOpts: BrowserOptions = {
headless: true,
args: ['--no-sandbox'],
observe: false,
};
const navOpts: NavigationOptions = {
navigationTimeout: 30000,
waitForEvents: ['networkIdle'],
};
(async () => {
await openBrowser(browserOpts);
await goto('https://example.com/login', navOpts);
await write('user@example.com', into(textBox('Email')));
await write('password123', into(textBox('Password')));
await click(button('Sign In'));
await closeBrowser();
})();
Using Intercept Types
import { openBrowser, goto, intercept, closeBrowser } from 'taiko';
import type { InterceptRequest } from 'taiko';
(async () => {
await openBrowser();
await intercept('https://api.example.com/data', async (request: InterceptRequest) => {
// Type-safe access to request properties
console.log(request.request.url);
console.log(request.request.method);
await request.respond({ body: JSON.stringify({ mocked: true }) });
});
await goto('https://example.com');
await closeBrowser();
})();
Leveraging Element Wrapper Types
import { openBrowser, goto, $, text, near, closeBrowser } from 'taiko';
import type { ElementWrapper, DollarWrapper } from 'taiko';
(async () => {
await openBrowser();
await goto('https://example.com');
// DollarWrapper extends ElementWrapper
const header: DollarWrapper = $('h1.title');
const exists: boolean = await header.exists();
const content: string = await header.text();
// Proximity selector returns RelativeSearchElement
const priceLabel = text('Price', near(text('Product A')));
const isVisible: boolean = await priceLabel.isVisible();
await closeBrowser();
})();