UNPKG

@assert-equals/dappdriver

Version:

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

86 lines (85 loc) 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DropDown = void 0; const constants_1 = require("../constants"); const drop_down_1 = require("../playwright/drop-down"); const dapp_driver_1 = require("../session/dapp-driver"); const drop_down_2 = require("../webdriver/drop-down"); const html_element_1 = require("./html-element"); /** * * * @export * @class DropDown * @extends {HTMLElement} * @implements {IDropDown} */ class DropDown extends html_element_1.HTMLElement { /** * Creates an instance of DropDown. * @param {string} cssLocator * @memberof DropDown */ constructor(cssLocator) { super(cssLocator); } /** * * * @protected * @param {(keyof IHTMLElement | keyof IDropDown)} methodName * @param {Array<any>} [args=[]] * @return {*} {Promise<any>} * @memberof DropDown */ async callIfMethodExists(methodName, args = []) { let dropdown; if (dapp_driver_1.DappDriver.Instance.Framework === constants_1.PLAYWRIGHT) { dropdown = new drop_down_1.PlaywrightDropDown(this.cssLocator); } else if (dapp_driver_1.DappDriver.Instance.Framework === constants_1.WEBDRIVER) { dropdown = new drop_down_2.WebDriverDropDown(this.cssLocator); } return await dropdown[methodName](...args); } /** * * Schedules a command to retrieve the selected option in this element * @return {*} {Promise<string>} * @memberof DropDown */ async getSelectedOption() { return await this.callIfMethodExists('getSelectedOption'); } /** * * Schedules a command to select an option in this element * @param {number} index * @return {*} {Promise<void>} * @memberof DropDown */ async selectByIndex(index) { return await this.callIfMethodExists('selectByIndex', [index]); } /** * * Schedules a command to select an option in this element * @param {string} text * @return {*} {Promise<void>} * @memberof DropDown */ async selectByText(text) { return await this.callIfMethodExists('selectByText', [text]); } /** * * Schedules a command to select an option in this element * @param {string} value * @return {*} {Promise<void>} * @memberof DropDown */ async selectByValue(value) { return await this.callIfMethodExists('selectByValue', [value]); } } exports.DropDown = DropDown;