flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
234 lines • 9.35 kB
JavaScript
"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 trailers() {
return helpers_1.wrapAsValue(this.context, this.httpResponse.trailers, "HTTP Trailers");
}
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 method() {
return helpers_1.wrapAsValue(this.context, this._httpResponse.method, "Method");
}
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(..._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) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error(`This scenario type (${this.responseTypeName}) does not support waitForHidden.`);
});
}
waitForVisible(..._args) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error(`This scenario type (${this.responseTypeName}) does not support waitForVisible.`);
});
}
waitForExists(..._args) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error(`This scenario type (${this.responseTypeName}) does not support waitForExists.`);
});
}
waitForNotExists(..._args) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error(`This scenario type (${this.responseTypeName}) does not support waitForNotExists.`);
});
}
waitForHavingText(..._args) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error(`This scenario type (${this.responseTypeName}) does not support waitForHavingText.`);
});
}
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;
});
}
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.$,
};
}
}
exports.ProtoResponse = ProtoResponse;
//# sourceMappingURL=response.js.map