UNPKG

@progress/kendo-e2e

Version:

Kendo UI end-to-end test utilities.

175 lines (174 loc) 7.96 kB
import { By, ThenableWebDriver, WebElement, WebElementCondition } from "selenium-webdriver"; import { WaitCondition } from "./conditions"; import { ExpectApi } from "./expect"; /** * This class encapsulates common location and interaction functionality over a {@link ThenableWebDriver}. */ export declare class WebApp { driver: ThenableWebDriver; constructor(driver: ThenableWebDriver); find(locator: By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<WebElement>; findAll(locator: By | string): Promise<WebElement[]>; findAllWithTimeout(locator: By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<WebElement[]>; findChild(rootElement: WebElement | By | string, locator: By | string, { waitForChild, timeout, pollTimeout }?: { waitForChild?: boolean; timeout?: number; pollTimeout?: number; }): Promise<WebElement>; findChildren(rootElement: WebElement | By | string, locator: By | string, { waitForChild, timeout, pollTimeout }?: { waitForChild?: boolean; timeout?: number; pollTimeout?: number; }): Promise<WebElement[]>; click(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; hover(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; focus(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; contextClick(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; doubleClick(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; waitForAnimationAndClick(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; scrollAndClick(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; scrollIntoView(locator: By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; dragTo(source: WebElement | By, target: WebElement | By): Promise<void>; dragByOffset(element: WebElement | By | string, offsetX: number, offsetY: number): Promise<void>; type(element: WebElement | By | string, text: string, { clear, sendEnter }?: { clear?: boolean; sendEnter?: boolean; }): Promise<void>; sendKey(key: string): Promise<void>; sendKeyCombination(key1: string, key2: string): Promise<void>; sendKeysCombination(keys: string[]): Promise<void>; sendControlKeyCombination(key: string): Promise<void>; isVisible(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<boolean>; isNotVisible(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<boolean>; isInViewport(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<boolean>; isNotInViewport(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<boolean>; hasFocus(element: WebElement | By | string): Promise<boolean>; hasNoFocus(element: WebElement | By | string): Promise<boolean>; hasText(element: WebElement | By | string, text: string): Promise<boolean>; hasValue(element: WebElement | By | string, value: string): Promise<boolean>; hasAttribute(element: WebElement | By | string, attribute: string, value: string, exactMatch?: boolean): Promise<boolean>; hasClass(element: WebElement | By | string, value: string, exactMatch?: boolean): Promise<boolean>; sleep(milliseconds: number): Promise<void>; wait(condition: WebElementCondition | WaitCondition, { timeout, message, pollTimeout }?: { timeout?: number; message?: string; pollTimeout?: number; }): Promise<void>; waitSafely(condition: WebElementCondition | WaitCondition, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<boolean>; waitForAnimation(element: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; getScreenshot(): Promise<string>; executeScript(script: string | ((...args: unknown[]) => unknown)): Promise<unknown>; getText(element: WebElement | By | string): Promise<string>; getAttribute(element: WebElement | By | string, attribute: string): Promise<string>; getProperty(element: WebElement | By | string, property: string): Promise<string>; getColor(element: WebElement | By | string): Promise<string>; getBackgroundColor(element: WebElement | By | string): Promise<string>; /** * Hides the text caret either globally (all input & textarea elements) or for a specific element. * * When no element is provided, a <style> tag is injected that sets caret-color to transparent * for all input and textarea elements. This is reversible only by page reload or manually removing * the injected style element. * * When an element is provided (WebElement, By locator, or CSS selector string), the element is * located (if needed) and its caret color is set to transparent. * * @param element Optional element whose caret should be hidden (WebElement instance, By locator, or CSS selector string). * @param options Optional timeout and pollTimeout for element location. */ hideCursor(element?: WebElement | By | string, { timeout, pollTimeout }?: { timeout?: number; pollTimeout?: number; }): Promise<void>; /** * Creates an expectation API for the specified element selector. * This provides a fluent interface for asserting element states with automatic retry logic. * The expect API will continuously retry finding the element and checking the condition * until it passes or the timeout is reached (default: 3000ms). * * @param selector - CSS selector string or By locator to identify the element * @returns ExpectApi object with assertion methods * * @example * ```typescript * // Assert element has specific text (default 3s timeout) * await app.expect('#result').toHaveText('Welcome user'); * * // Assert element is visible * await app.expect('.modal').toBeVisible(); * * // Assert element is not visible * await app.expect('.spinner').not.toBeVisible(); * * // Assert with custom timeout and message * await app.expect('#message').toHaveText('Success', { * timeout: 5000, * message: 'Failed to load results.' * }); * * // Assert using regex pattern * await app.expect('#status').toHaveText(/completed|success/i, { timeout: 10000 }); * * // Assert element has value * await app.expect('#input').toHaveValue('expected value', { timeout: 2000 }); * * // Assert element has focus * await app.expect('#activeInput').toHaveFocus(); * * // Assert element has attribute * await app.expect('#btn').toHaveAttribute('disabled', 'true'); * * // Assert element has class (partial match) * await app.expect('#div').toHaveClass('active', { exactMatch: false }); * ``` */ expect(selector: string | By): ExpectApi; }