@progress/kendo-e2e
Version:
Kendo UI end-to-end test utilities.
130 lines (129 loc) • 5.4 kB
TypeScript
import { By, IRectangle, ThenableWebDriver } from "selenium-webdriver";
import { Level } from "selenium-webdriver/lib/logging";
import { WebApp } from "./web-app";
export { By, Key, ThenableWebDriver, until, WebElement, WebElementCondition } from "selenium-webdriver";
interface BrowserOptions {
driver?: ThenableWebDriver;
mobileEmulation?: {
deviceName: string;
} | {
width: number;
height: number;
pixelRatio: number;
} | any;
enableBidi?: boolean;
}
/**
* Extends the {@link WebApp} with browser based capabilities.
* Essentially, we test browsers (that have nice things like {@link navigateTo}, {@link refresh} etc.),
* and electron apps, that render within a webview (but have no shell with address bar, refresh button, tabs, etc),
* and VSCode extensions... which is an electron app.
*/
export declare class Browser extends WebApp {
/**
* Creates an instance of the Browser class.
*
* @param {ThenableWebDriver | BrowserOptions} [driverOrOptions] - Either a WebDriver instance or an options object.
* If a WebDriver instance is provided, it will be used as the driver. If an options object is provided, a new driver will be created with those options.
* @param {Object} [mobileEmulation] - (Optional) Mobile emulation options, used only if the first parameter is a WebDriver instance.
* Mobile options can be an object with either a `deviceName` or `width`, `height`, and `pixelRatio`.
* @param {boolean} [enableBidi] - (Optional) Enables BiDi (Bidirectional communication) if set to `true`.
*
* __Usage Examples:__
*
* __Example 1: Using a Pre-configured Device__
* ```typescript
* const mobileEmulation = { deviceName: "iPhone 14 Pro Max" };
* const browser = new Browser(mobileEmulation);
* ```
*
* __Example 2: Using Custom Screen Configuration__
* ```typescript
* const mobileEmulation = { deviceMetrics: { width: 360, height: 640, pixelRatio: 3.0 }, userAgent: 'My Agent' };
* const browser = new Browser(mobileEmulation);
* ```
*
* __Example 3: Providing a WebDriver Instance With Mobile Emulation__
* ```typescript
* const driver = new Builder().forBrowser('chrome').build();
* const mobileEmulation = { deviceName: "iPhone 14 Pro Max" };
* const browser = new Browser(driver, mobileEmulation);
* ```
*
* __Example 4: Enabling BiDi Mode__
* ```typescript
* const browser = new Browser({ enableBidi: true });
* ```
*
* __Example 5: Combining Mobile Emulation and BiDi Mode__
* ```typescript
* const browser = new Browser({ mobileEmulation: { deviceName: "iPhone 14 Pro Max" }, enableBidi: true });
* ```
*
* [em]: https://chromedriver.chromium.org/mobile-emulation
* [devem]: https://developer.chrome.com/devtools/docs/device-mode
*/
constructor(driverOrOptions?: ThenableWebDriver | BrowserOptions, mobileEmulation?: {
deviceName: string;
} | {
width: number;
height: number;
pixelRatio: number;
} | any, enableBidi?: boolean);
close(): Promise<void>;
navigateTo(url: string): Promise<void>;
getRect(): Promise<IRectangle>;
setRect(rect: {
width?: number;
height?: number;
x?: number;
y?: number;
}): Promise<void>;
resizeToDocumentScrollHeight(): Promise<void>;
/**
* Resizes the browser window to the specified width and height.
*
* @param width - The new width of the window in pixels
* @param height - The new height of the window in pixels
* @throws Error if the window resize operation fails
*
* @example
* ```typescript
* // Resize window to 1920x1080
* await browser.resizeWindow(1920, 1080);
*
* // Resize to mobile size
* await browser.resizeWindow(375, 667);
* ```
*/
resizeWindow(width: number, height: number): Promise<void>;
refresh(): Promise<void>;
switchToIFrame(elementLocator: By): Promise<void>;
getCurrentUrl(): Promise<string>;
getBrowserName(): Promise<string>;
getAccessibilityViolations(cssSelector?: string, disableRules?: string[]): Promise<[]>;
clearLogs(): Promise<void>;
getErrorLogs(excludeList?: string[], logLevel?: Level): Promise<string[]>;
/**
* Executes a JavaScript script in the browser context.
*
* @param script - The JavaScript code to execute as a string
* @param waitBeforeMs - Optional wait time in milliseconds before executing the script (default: 0)
* @param waitAfterMs - Optional wait time in milliseconds after executing the script (default: 0)
* @returns Promise<unknown> - The result of the script execution
* @throws Error if the script execution fails
*
* @example
* ```typescript
* // Basic script execution
* const result = await browser.executeScript('return document.title;');
*
* // With wait before execution
* await browser.executeScript('document.body.style.background = "red";', 1000);
*
* // With waits before and after execution
* const height = await browser.executeScript('return document.body.scrollHeight;', 500, 200);
* ```
*/
executeScript(script: string, waitBeforeMs?: number, waitAfterMs?: number): Promise<unknown>;
}