UNPKG

@assert-equals/dappdriver

Version:

DappDriver is an e2e testing framework designed for testing decentralized applications (dApps) using MetaMask, Rainbow or Zerion

168 lines (167 loc) 5.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HTMLElement = void 0; const constants_1 = require("../constants"); const html_element_1 = require("../playwright/html-element"); const dapp_driver_1 = require("../session/dapp-driver"); const utils_1 = require("../utils"); const html_element_2 = require("../webdriver/html-element"); /** * * * @export * @class HTMLElement * @implements {IHTMLElement} */ class HTMLElement { cssLocator; element; timeout; /** * Creates an instance of HTMLElement. * @param {string} cssLocator * @param {number} [timeout=20000] * @param {*} [element=null] * @memberof HTMLElement */ constructor(cssLocator, timeout = 20000, element = null) { this.cssLocator = cssLocator; this.element = element; this.timeout = timeout; } /** * * * @protected * @param {keyof IHTMLElement} methodName * @param {Array<any>} [args=[]] * @return {*} {Promise<any>} * @memberof HTMLElement */ async callIfMethodExists(methodName, args = []) { let htmlElement; if (dapp_driver_1.DappDriver.Instance.Framework === constants_1.PLAYWRIGHT) { htmlElement = new html_element_1.PlaywrightHTMLElement(this.cssLocator, this.timeout, this.element); } else if (dapp_driver_1.DappDriver.Instance.Framework === constants_1.WEBDRIVER) { htmlElement = new html_element_2.WebDriverHTMLElement(this.cssLocator, this.timeout, this.element); } return await htmlElement[methodName](...args); } async click(page) { if (page) { return await this.callIfMethodExists('click', [page]); } else { return await this.callIfMethodExists('click'); } } /** * * Schedules a command to click on this element and switch the focus of all future commands to a given window * @template TPage * @param {new () => TPage} page * @return {*} {Promise<TPage>} * @memberof HTMLElement */ async clickAndSwitchToWindow(page) { return await this.callIfMethodExists('clickAndSwitchToWindow', [page]); } /** * * Schedules a command to click on this element and wait for the given amount of time * @param {number} [duration=1000] * @return {*} {Promise<void>} * @memberof HTMLElement */ async clickAndWait(duration = 1000) { return await this.callIfMethodExists('clickAndWait', [duration]); } /** * * Schedules a command to query for the value of the given attribute of the element * @param {string} attribute * @return {*} {(Promise<string | null>)} * @memberof HTMLElement */ async getAttribute(attribute) { return await this.callIfMethodExists('getAttribute', [attribute]); } /** * * Schedules a command to query for the value of the given css property of the element * @param {string} property * @return {*} {(Promise<string | null>)} * @memberof HTMLElement */ async getCssValue(property) { return await this.callIfMethodExists('getCssValue', [property]); } /** * * Schedules a command to query for the visible innerText of the element * @return {*} {Promise<string>} * @memberof HTMLElement */ async getText() { return await this.callIfMethodExists('getText'); } /** * * Schedules a command to hover over this element * @return {*} {Promise<void>} * @memberof HTMLElement */ async hover() { return await this.callIfMethodExists('hover'); } /** * * Schedules a command to query whether this element is currently displayed * @return {*} {Promise<boolean>} * @memberof HTMLElement */ async isDisplayed() { return await this.callIfMethodExists('isDisplayed'); } /** * * Schedules a command to query whether the element is enabled * @return {*} {Promise<boolean>} * @memberof HTMLElement */ async isEnabled() { return await this.callIfMethodExists('isEnabled'); } /** * * Schedules a command to query whether the element is visible * @return {*} {Promise<boolean>} * @memberof HTMLElement */ async isVisible() { return await this.callIfMethodExists('isVisible'); } /** * * Schedules a command to type a sequence in the element * @param {string} keys * @return {*} {Promise<void>} * @memberof HTMLElement */ async type(keys) { return await this.callIfMethodExists('type', [keys]); } /** * * Schedules a command to wait for the visible innerText of the element * @param {(string | RegExp)} [text] * @return {*} {Promise<void>} * @memberof HTMLElement */ async waitForText(text) { text = text ? (0, utils_1.toRegExp)(text) : new RegExp(/.+/); return await this.callIfMethodExists('waitForText', [text]); } } exports.HTMLElement = HTMLElement;