UNPKG

flagpole

Version:

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

250 lines 10.2 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 = void 0; const url_1 = require("url"); const http_response_1 = require("./http/http-response"); const assertion_context_1 = require("./assertion/assertion-context"); const helpers_1 = require("./helpers"); const value_promise_1 = require("./value-promise"); class ProtoResponse { constructor(scenario) { this.scenario = scenario; this._currentUrl = null; this._httpResponse = http_response_1.createEmptyResponse(); this._currentUrl = scenario.finalUrl; } init(res) { this._httpResponse = res; } get context() { return new assertion_context_1.AssertionContext(this.scenario, this); } eval(callback, ...args) { return __awaiter(this, void 0, void 0, function* () { throw "This type of scenario does not suport eval."; }); } 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, "Response Body String"); } get rawBody() { return helpers_1.wrapAsValue(this.context, this.httpResponse.rawBody, "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 trailers() { return helpers_1.wrapAsValue(this.context, this.httpResponse.trailers, "HTTP Trailers"); } get jsonBody() { return helpers_1.wrapAsValue(this.context, this.httpResponse.jsonBody, "JSON Body"); } 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 currentUrl() { return helpers_1.wrapAsValue(this.context, this.scenario.finalUrl, "Current URL"); } 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 method() { return helpers_1.wrapAsValue(this.context, this.httpResponse.method, "Method"); } navigate(req) { return __awaiter(this, void 0, void 0, function* () { this._currentUrl = this.absolutizeUri(req.uri || ""); return this.init(yield req.fetch()); }); } absolutizeUri(uri) { return new url_1.URL(uri, this.scenario.buildUrl()).href; } getRoot() { return this.httpResponse.body; } getSource() { throw new Error(`This scenario type (${this.scenario.typeName}) does not support getSource.`); } 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(..._args) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForNavigation(..._args) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForLoad(..._args) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForReady(..._args) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForNetworkIdle(..._args) { return __awaiter(this, void 0, void 0, function* () { return this.context.pause(1); }); } waitForHidden(..._args) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support waitForHidden.`); } waitForVisible(..._args) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support waitForVisible.`); } waitForExists(..._args) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support waitForExists.`); } waitForNotExists(..._args) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support waitForNotExists.`); } waitForHavingText(..._args) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support waitForHavingText.`); } screenshot() { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.scenario.typeName}) does not support screenshots.`); }); } type(selector, textToType, opts = {}) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support type.`); } clear(selector) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support clear.`); } clearThenType(selector, textToType, opts = {}) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support clearThenType.`); } waitForXPath(xPath) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support waitForXPath.`); } findXPath(xPath) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support findXPath.`); } findAllXPath(xPath) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.scenario.typeName}) does not support findAllXPath.`); }); } findHavingText(selector, searchForText) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support findHavingText.`); } findAllHavingText(selector, searchForText) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.scenario.typeName}) does not support findAllHavingText.`); }); } selectOption(selector, value) { throw new Error(`This scenario type (${this.scenario.typeName}) does not support selectOption.`); } movePointer(...pointers) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.scenario.typeName}) does not support pointer.`); }); } gesture(type, opts) { return __awaiter(this, void 0, void 0, function* () { throw new Error(`This scenario type (${this.scenario.typeName}) does not support gesture.`); }); } scrollTo(_point) { return __awaiter(this, void 0, void 0, function* () { return this; }); } click(selector, a, b) { return value_promise_1.ValuePromise.execute(() => __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; })); } serialize() { return { statusCode: this.statusCode.$, statusMessage: this.statusMessage.$, url: this.url.toString(), finalURl: this.finalUrl.toString(), body: this.body.toString(), jsonBody: this.jsonBody.$, loadTime: this.loadTime.$, length: this.length.$, method: this.context.request.method.toString(), headers: this.headers.$, cookies: this.cookies.$, trailers: this.trailers.$, }; } rotateScreen(rotation) { return __awaiter(this, void 0, void 0, function* () { throw "rotateScreen not implemented for this kind of scenario."; }); } getScreenProperties() { return __awaiter(this, void 0, void 0, function* () { throw "getScreenProperties not implemented for this kind of scenario."; }); } hideKeyboard() { return __awaiter(this, void 0, void 0, function* () { throw "hideKeyboard not implemented for this kind of scenario."; }); } } exports.ProtoResponse = ProtoResponse; //# sourceMappingURL=response.js.map