@openfin/automation-helpers
Version:
Helper methods for automation testing in the OpenFin ecosystem
131 lines (130 loc) • 5 kB
TypeScript
import type OpenFin from "@openfin/core";
import type { IWebDriver } from "../models/IWebDriver";
import type { IWebDriverWindow } from "../models/IWebDriverWindow";
import type { WindowLocatorTypes } from "../models/windowLocatorTypes";
import type { WindowLocatorValueTypes } from "../models/windowLocatorValueTypes";
/**
* BaseWebDriver with common methods.
*/
export declare abstract class BaseWebDriver<T, U extends IWebDriverWindow> implements Partial<IWebDriver> {
/**
* The node web driver to make the chromedriver calls with.
*/
protected _client?: T;
/**
* All the windows by their web driver handle.
*/
protected readonly _windowCache: {
[handle: string]: IWebDriverWindow;
};
/**
* Create a new instance of BaseWebDriver.
* @param client The client to use for chromedriver calls if already created.
*/
constructor(client?: T);
/**
* Get the details of all the connected windows.
* @returns The list of windows.
* @see https://w3c.github.io/webdriver/#dfn-get-window-handles
*/
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
*/
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.
*/
switchToWindow(locator: WindowLocatorTypes, locatorValue: WindowLocatorValueTypes, activateNativeWindow?: boolean): Promise<boolean>;
/**
* Get the title of the current window.
* @returns The window title.
* @see https://w3c.github.io/webdriver/#dfn-get-title
*/
getTitle(): Promise<string | undefined>;
/**
* Get the URL of the current window.
* @returns The window url.
* @see https://w3c.github.io/webdriver/#dfn-get-current-url
*/
getUrl(): Promise<string | undefined>;
/**
* Set the URL of the current window.
* @param url The url to navigate to.
* @see https://w3c.github.io/webdriver/#dfn-navigate-to
*/
setUrl(url: string): Promise<void>;
/**
* Get a window from the window cache and add it if not there.
* @param windowHandle The window handle to lookup.
* @returns The window information.
*/
private getWindowFromCacheByHandle;
/**
* Try and match a window use a locator.
* @param locatorValue The locator value.
* @param testValue The value to check.
* @returns True if the window matches.
* @throws TypeError if there is value type is not known.
*/
private locatorMatcher;
/**
* Try and match a window using the locator details.
* @param locator The locator type.
* @param locatorValue The locator value.
* @param webDriverWindow The window to match against.
* @returns True if the window matches the locator.
*/
private matchWindow;
/**
* Create the native window object.
* @param client The client.
* @param windowHandle The window handle.
* @param title The window title.
* @param url The window url.
* @param identity The window identity.
* @returns The native window.
*/
protected abstract createWebDriverWindow(client: T, windowHandle: string, title: string, url: string, identity: OpenFin.Identity | undefined): U;
/**
* Get the title of the current window.
* @returns The window title.
* @see https://w3c.github.io/webdriver/#dfn-get-title
*/
protected abstract safeGetTitle(): Promise<string | undefined>;
/**
* Get the URL of the current window.
* @returns The window url.
* @see https://w3c.github.io/webdriver/#dfn-get-current-url
*/
protected abstract safeGetUrl(): Promise<string | undefined>;
/**
* Set the URL of the current window.
* @param url The url to navigate to.
* @see https://w3c.github.io/webdriver/#dfn-navigate-to
*/
protected abstract safeSetUrl(url: string): Promise<void>;
/**
* Get the window handle and catch exceptions.
* @returns The window handle if available.
*/
protected abstract safeGetWindowHandle(): Promise<string | undefined>;
/**
* Get the window handles and catch exceptions.
* @returns The window handles if available.
*/
protected abstract safeGetWindowHandles(): Promise<string[]>;
/**
* Switch to the window handle and catch exceptions.
* @param handle The window to switch to.
* @param activateNativeWindow Activate the native window as well.
* @returns True if switched to the window.
*/
protected abstract safeSwitchToWindow(handle: string, activateNativeWindow: boolean): Promise<boolean>;
}