UNPKG

@openfin/automation-helpers

Version:

Helper methods for automation testing in the OpenFin ecosystem

246 lines (245 loc) 11.6 kB
import type { IWebDriverElement } from "../models/IWebDriverElement"; import type { IWebDriverWindow } from "../models/IWebDriverWindow"; import type { LocatorTypes } from "../models/locatorTypes"; import type { WebDriverAction } from "../models/webDriverAction"; import type { WindowLocatorTypes } from "../models/windowLocatorTypes"; import type { WindowLocatorValueTypes } from "../models/windowLocatorValueTypes"; /** * Global webdriver wrapper with non driver specific code. */ export declare class WebDriver { /** * Execute async script. * @param script The script to execute. * @param args Arguments to pass to the execute method. * @returns The result from the call. */ static executeAsync<T>(script: string, args?: (string | object | number | boolean | undefined)[]): Promise<T>; /** * Call the execute async script for the specified method. * @param method The method to call in the global scope. * @param params Parameters to call the object with. * @param awaitReturn Await the return from the method. * @returns The result from the call. */ static callMethod<T>(method: string, params?: (string | object | number | boolean | undefined)[], awaitReturn?: boolean): Promise<T>; /** * Call a JavaScript method until a condition is met, or timed out. * @param method The method to call on the OpenFin object. * @param params Parameters to call the object with. * @param callAsync Call the method as async. * @param condition Condition to test before returning. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The result from the call. */ static callMethodUntilCondition<T>(method: string, params: (string | object | number | boolean | undefined)[] | undefined, callAsync: boolean, condition: (result: T | Error) => boolean, timeoutMs?: number, intervalMs?: number): Promise<T | Error | unknown>; /** * Wait for an object to exist in the windows namespace. * @param objectPath The name of the object to wait for. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The object if it exists. */ static waitForObjectExisting<T>(objectPath: string, timeoutMs?: number, intervalMs?: number): Promise<T | undefined>; /** * Sleep for the specified milliseconds. * @param ms The milliseconds to sleep for. * @returns Nothing. */ static sleep(ms: number): Promise<void>; /** * Get the title of the current window. * @returns The window title. */ static getTitle(): Promise<string | undefined>; /** * Get the URL of the current window. * @returns The window title. */ static getUrl(): Promise<string | undefined>; /** * Set the URL of the current window. * @param url The url to navigate to. * @returns Nothing. * @see https://w3c.github.io/webdriver/#dfn-navigate-to */ static setUrl(url: string): Promise<void>; /** * Get the details of all the connected windows. * @returns The list of windows. * @see https://w3c.github.io/webdriver/#dfn-get-window-handles */ static getWindows(): Promise<IWebDriverWindow[]>; /** * Get the details of the current window. * @returns The current window if available. * @see https://w3c.github.io/webdriver/#dfn-get-window-handle */ static getWindow(): Promise<IWebDriverWindow | undefined>; /** * Switch to a window by locator. * @param locator The locator type. * @param locatorValue The window locator value to use. * @param activateNativeWindow Activate the native window as well. * @returns True if the window was available. */ static switchToWindow(locator: WindowLocatorTypes, locatorValue: WindowLocatorValueTypes, activateNativeWindow?: boolean): Promise<boolean>; /** * Wait for a window by its locator. * @param locator The locator type. * @param locatorValue The window locator value to use. * @param timeoutMs The maximum amount of time to wait in seconds. * @param intervalMs The amount of time between checks. * @param activateNativeWindow Activate the native window as well. * @returns True if the window was found. */ static waitForWindow(locator: WindowLocatorTypes, locatorValue: WindowLocatorValueTypes, timeoutMs?: number, intervalMs?: number, activateNativeWindow?: boolean): Promise<boolean>; /** * Find an element by its xpath. * @param elementPath The path the element to find. * @returns The element if found. */ static findElementByPath(elementPath: string): Promise<IWebDriverElement | undefined>; /** * Wait for an element by its xpath. * @param elementPath The path the element to find. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The element if found or undefined if not found within timeout. */ static waitForElementByPath(elementPath: string, timeoutMs?: number, intervalMs?: number): Promise<IWebDriverElement | undefined>; /** * Find elements by their xpath. * @param elementPath The path the element to find. * @returns The element if found. */ static findElementsByPath(elementPath: string): Promise<IWebDriverElement[]>; /** * Find an element by its tag. * @param tag The tag of the element to find. * @returns The element if found. */ static findElementByTag(tag: string): Promise<IWebDriverElement | undefined>; /** * Find all elements by their tag. * @param tag The tag of the element to find. * @returns The elements if found. */ static findElementsByTag(tag: string): Promise<IWebDriverElement[]>; /** * Wait for an element by its tag. * @param tag The tag of the element to find. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The element if found or undefined if not found within timeout. */ static waitForElementByTag(tag: string, timeoutMs?: number, intervalMs?: number): Promise<IWebDriverElement | undefined>; /** * Find an element by css selector. * @param cssSelector The css selector of the element to find. * @returns The element if found. */ static findElementByCssSelector(cssSelector: string): Promise<IWebDriverElement | undefined>; /** * Find all elements by their css selector. * @param cssSelector The css selector of the element to find. * @returns The element if found. */ static findElementsCssSelector(cssSelector: string): Promise<IWebDriverElement[]>; /** * Wait for an element by its css selector. * @param cssSelector The css selector of the element to find. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The element if found or undefined if not found within timeout. */ static waitForElementByCssSelector(cssSelector: string, timeoutMs?: number, intervalMs?: number): Promise<IWebDriverElement | undefined>; /** * Find an element by its id. * @param id The id of the element to find. * @returns The element if found. */ static findElementById(id: string): Promise<IWebDriverElement | undefined>; /** * Wait for an element by its id. * @param id The id of the element to find. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The element if found or undefined if not found within timeout. */ static waitForElementById(id: string, timeoutMs?: number, intervalMs?: number): Promise<IWebDriverElement | undefined>; /** * Find an element by its class. * @param className The class of the element to find. * @param tag The tag of the element to find defaults to all. * @returns The element if found. */ static findElementByClass(className: string, tag?: string): Promise<IWebDriverElement | undefined>; /** * Find all elements by their class. * @param className The class of the element to find. * @param tag The tag of the element to find defaults to all. * @returns The element if found. */ static findElementsByClass(className: string, tag?: string): Promise<IWebDriverElement[]>; /** * Wait for an element by its class. * @param className The class of the element to find. * @param tag The tag of the element to find defaults to all. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The element if found or undefined if not found within timeout. */ static waitForElementByClass(className: string, tag?: string, timeoutMs?: number, intervalMs?: number): Promise<IWebDriverElement | undefined>; /** * Find an element. * @param locator The locator to use when finding the element. * @param value The value to use with the locator. * @returns The element if found. */ static findElementByLocator(locator: LocatorTypes, value: string): Promise<IWebDriverElement | undefined>; /** * Find elements. * @param locator The locator to use when finding the elements. * @param value The value to use with the locator. * @returns The elements if found. */ static findElementsByLocator(locator: LocatorTypes, value: string): Promise<IWebDriverElement[]>; /** * Wait for an element by its locator. * @param locator The locator to use when finding the elements. * @param value The value to use with the locator. * @param timeoutMs The amount of time to wait for the object. * @param intervalMs The amount of time between checks. * @returns The element if found or undefined if not found within timeout. */ static waitForElementByLocator(locator: LocatorTypes, value: string, timeoutMs?: number, intervalMs?: number): Promise<IWebDriverElement | undefined>; /** * Wait until a condition is met. * @param condition The condition to check. * @param timeoutMs The amount of time to wait for the condition. * @param intervalMs The amount of time between checks. * @returns The result of the condition check. */ static waitForCondition(condition: () => Promise<boolean>, timeoutMs?: number, intervalMs?: number): Promise<boolean>; /** * Take a screenshot of the whole page. * @returns Returns a base64 encoded png. */ static screenshot(): Promise<string>; /** * Take a screenshot of the whole page and saves it. * @param folder The location to save the screen grab, if not provided defaults to config location. * @param filename The filename to save the screen grab, if not provided defaults fixed naming. * @returns Returns the final filename. */ static saveScreenshot(folder?: string, filename?: string): Promise<void>; /** * Perform actions on the webdriver. * @param actions The actions to perform. * @returns True if the actions were successfully performed. */ static actions(actions: WebDriverAction[]): Promise<boolean>; static ofMapProxyNames<T>(obj: T): T; }