UNPKG

@assert-equals/dappdriver

Version:

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

83 lines (82 loc) 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightHTMLElement = void 0; const page_1 = require("../page"); const dapp_driver_1 = require("../session/dapp-driver"); class PlaywrightHTMLElement { page; frame; webElement; element; timeout; constructor(cssLocator, timeout = 20000, element = null) { this.page = dapp_driver_1.DappDriver.Instance.Page; this.frame = dapp_driver_1.DappDriver.Instance.Frame; this.element = element; this.timeout = timeout; this.webElement = this.getWebElement(cssLocator); } getWebElement(cssLocator) { let locator; if (this.element) { locator = this.element; } else { locator = !this.frame ? this.page.locator(cssLocator) : this.frame.locator(cssLocator); } return locator; } async click(page) { await this.webElement.click({ timeout: this.timeout }); if (page) { return await dapp_driver_1.DappDriver.getPage(page); } } async clickAndWait(duration) { await this.click(); await dapp_driver_1.DappDriver.sleep(duration); } async clickAndOpensInNewWindow(page) { await this.click(); await new page_1.PageObject().opensInNewWindow(); if (page) { return await dapp_driver_1.DappDriver.getPage(page); } } async clickAndOpensInWindow(page) { await this.click(); return await new page_1.PageObject().opensInWindow(page); } async clickAndSwitchToMainWindow(page) { await this.click(); await new page_1.PageObject().switchToMainWindow(); if (page) { return await dapp_driver_1.DappDriver.getPage(page); } } async getAttribute(attribute) { return await this.webElement.getAttribute(attribute, { timeout: this.timeout }); } async getCssValue(property) { return await this.webElement.evaluate((element, property) => window.getComputedStyle(element).getPropertyValue(property), property); } async getText() { return await this.webElement.innerText({ timeout: this.timeout }); } async hover() { return await this.webElement.hover({ timeout: this.timeout }); } async isDisplayed() { return (await this.webElement.count()) > 0; } async isEnabled() { return await this.webElement.isEnabled({ timeout: this.timeout }); } async isVisible() { return await this.webElement.isVisible({ timeout: this.timeout }); } async type(keys) { await this.webElement.pressSequentially(keys, { timeout: this.timeout }); } } exports.PlaywrightHTMLElement = PlaywrightHTMLElement;