UNPKG

flagpole

Version:

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

65 lines 2.83 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const response_1 = require("./response"); class DOMResponse extends response_1.ProtoResponse { findAllHavingText(selector, searchForText) { return __awaiter(this, void 0, void 0, function* () { if (this.isBrowser && this.context.page === null) { throw new Error('No page object was found.'); } let matchingElements = []; const elements = yield this.findAll(selector); for (let i = 0; i < elements.length; i++) { const element = elements[i]; const text = yield element.getText(); if (typeof searchForText == 'string') { if (text.toString() == String(searchForText)) { matchingElements.push(element); } } else { if (searchForText.test(text.toString())) { matchingElements.push(element); } } } return matchingElements; }); } ; findHavingText(selector, searchForText) { return __awaiter(this, void 0, void 0, function* () { if (this.isBrowser && this.context.page === null) { throw new Error('No page object was found.'); } let matchingElement = null; const elements = yield this.findAll(selector); for (let i = 0; i < elements.length && matchingElement === null; i++) { const element = elements[i]; const text = yield element.getText(); if (typeof searchForText == 'string') { if (text.toString() == String(searchForText)) { matchingElement = element; } } else { if (searchForText.test(text.toString())) { matchingElement = element; } } } return matchingElement; }); } ; } exports.DOMResponse = DOMResponse; //# sourceMappingURL=domresponse.js.map