UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

101 lines 3.79 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PuppeteerElement = void 0; const dom_element_1 = require("../html/dom-element"); const value_promise_1 = require("../value-promise"); class PuppeteerElement extends dom_element_1.DOMElement { get _page() { const scenario = this.context.scenario; if (scenario.page === null) { throw "Puppeteer page object was not found."; } return scenario.page; } constructor(input, context, name, path) { super(input, context, name, path); } toString() { return String(this.path); } clearThenType(textToType, opts = {}) { return value_promise_1.ValuePromise.execute(() => __awaiter(this, void 0, void 0, function* () { yield this.clear(); yield this.type(textToType, opts); return this; })); } eval(js) { return __awaiter(this, void 0, void 0, function* () { return this._eval(js); }); } waitForFunction(js, a, ...args) { return value_promise_1.ValuePromise.execute(() => __awaiter(this, void 0, void 0, function* () { const opts = typeof a == "number" ? { timeout: a } : a || {}; try { yield this._page.waitForFunction.apply(this._page, [ js, opts, ...[this.$, ...args], ]); this._completedAction("WAIT", this.name); } catch (_a) { this._failedAction("WAIT", this.name); } return this; })); } waitForHidden(timeout) { return value_promise_1.ValuePromise.wrap(this); } waitForVisible(timeout) { return value_promise_1.ValuePromise.wrap(this); } _getSourceCode() { return __awaiter(this, void 0, void 0, function* () { this._sourceCode = yield this._getOuterHtml(); return this._sourceCode; }); } _eval(js, arg) { return this._page.evaluate(js, arg); } _getProperty(key) { return __awaiter(this, void 0, void 0, function* () { return (yield this._input.getProperty(key)).jsonValue(); }); } _waitForIt(fn, verb, timeout) { return value_promise_1.ValuePromise.execute(() => __awaiter(this, void 0, void 0, function* () { try { yield this._waitForFunction(fn, timeout); this._completedAction(verb.toUpperCase(), this.name); } catch (e) { this._failedAction(verb.toUpperCase(), this.name); } return this; })); } _waitForFunction(fn, timeout) { return __awaiter(this, void 0, void 0, function* () { const opts = { timeout: timeout, }; yield this._page.waitForFunction(fn, opts, this.$); return this; }); } } exports.PuppeteerElement = PuppeteerElement; //# sourceMappingURL=puppeteer-element.js.map