UNPKG

flagpole

Version:

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

211 lines 8.46 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.ProtoResponse = exports.isPuppeteer = void 0; const url_1 = require("url"); const httpresponse_1 = require("./httpresponse"); const assertioncontext_1 = require("./assertioncontext"); const helpers_1 = require("./helpers"); function isPuppeteer(type) { return ["browser", "extjs"].indexOf(type) >= 0; } exports.isPuppeteer = isPuppeteer; class ProtoResponse { constructor(scenario) { this._httpResponse = httpresponse_1.HttpResponse.createEmpty(); this.scenario = scenario; } get isBrowser() { return false; } get httpResponse() { return this._httpResponse; } get statusCode() { return helpers_1.wrapAsValue(this.context, this.httpResponse.statusCode, "HTTP Status Code"); } get statusMessage() { return helpers_1.wrapAsValue(this.context, this.httpResponse.statusMessage, "HTTP Status Message"); } get body() { return helpers_1.wrapAsValue(this.context, this.httpResponse.body, "Raw Response Body"); } get length() { return helpers_1.wrapAsValue(this.context, this.httpResponse.body.length, "Length of Response Body"); } get headers() { return helpers_1.wrapAsValue(this.context, this.httpResponse.headers, "HTTP Headers"); } get cookies() { return helpers_1.wrapAsValue(this.context, this.httpResponse.cookies, "HTTP Cookies"); } get jsonBody() { try { const json = JSON.parse(this.httpResponse.body); return helpers_1.wrapAsValue(this.context, json, "JSON Response"); } catch (ex) { return helpers_1.wrapAsValue(this.context, null, `JSON Response: ${ex}`); } } get url() { return helpers_1.wrapAsValue(this.context, this.scenario.url, "Request URL"); } get finalUrl() { return helpers_1.wrapAsValue(this.context, this.scenario.finalUrl, "Response URL (after redirects)"); } get redirectCount() { return helpers_1.wrapAsValue(this.context, this.scenario.redirectCount, "Response URL (after redirects)"); } get loadTime() { return helpers_1.wrapAsValue(this.context, this.scenario.requestDuration, "Request to Response Load Time"); } get context() { return new assertioncontext_1.AssertionContext(this.scenario, this); } init(httpResponse) { this._httpResponse = httpResponse; } absolutizeUri(uri) { return new url_1.URL(uri, this.scenario.buildUrl()).href; } getRoot() { return this.httpResponse.body; } header(key) { key = typeof this.httpResponse.headers[key] !== "undefined" ? key : key.toLowerCase(); const headerValue = this.httpResponse.headers[key]; return helpers_1.wrapAsValue(this.context, typeof headerValue == "undefined" ? null : headerValue, "HTTP Headers[" + key + "]"); } cookie(key) { return helpers_1.wrapAsValue(this.context, this.httpResponse.cookies[key], "HTTP Cookies[" + key + "]"); } waitForFunction(js, opts, ...args) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForNavigation(timeout = 10000, waitFor) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForLoad(timeout = 30000) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForReady(timeout = 30000) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForNetworkIdle(timeout = 30000) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForHidden(selector, timeout = 30000) { return __awaiter(this, void 0, void 0, function* () { yield this.context.pause(1); return helpers_1.wrapAsValue(this.context, null, selector); }); } waitForVisible(selector, timeout = 30000) { return __awaiter(this, void 0, void 0, function* () { yield this.context.pause(1); return helpers_1.wrapAsValue(this.context, null, selector); }); } waitForExists(selector, timeout = 30000) { return __awaiter(this, void 0, void 0, function* () { yield this.context.pause(1); return helpers_1.wrapAsValue(this.context, null, selector); }); } waitForHavingText(selector, text, timeout = 30000) { return __awaiter(this, void 0, void 0, function* () { yield this.context.pause(1); return helpers_1.wrapAsValue(this.context, null, selector); }); } screenshot() { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support screenshots.`); }); } type(selector, textToType, opts = {}) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support type.`); }); } clear(selector) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support clear.`); }); } waitForXPath(xPath) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support waitForXPath.`); }); } findXPath(xPath) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support findXPath.`); }); } findAllXPath(xPath) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support findAllXPath.`); }); } findHavingText(selector, searchForText) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support findHavingText.`); }); } findAllHavingText(selector, searchForText) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support findAllHavingText.`); }); } selectOption(selector, value) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.responseTypeName}) does not support selectOption.`); }); } scrollTo(_point) { return __awaiter(this, void 0, void 0, function* () { return this; }); } click(selector, a, b) { return __awaiter(this, void 0, void 0, function* () { const contains = typeof a == "string" ? a : undefined; const matches = a instanceof RegExp ? a : undefined; const opts = (b || a || {}); const element = contains ? yield this.find(selector, contains, opts) : matches ? yield this.find(selector, matches, opts) : yield this.find(selector, opts); if (!(yield element.exists()).isNull()) { return element.click(); } return element; }); } } exports.ProtoResponse = ProtoResponse; //# sourceMappingURL=response.js.map