flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
187 lines • 7.24 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 });
const url_1 = require("url");
const value_1 = require("./value");
const httpresponse_1 = require("./httpresponse");
const assertioncontext_1 = require("./assertioncontext");
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 this._wrapAsValue(this.httpResponse.statusCode, "HTTP Status Code");
}
get statusMessage() {
return this._wrapAsValue(this.httpResponse.statusMessage, "HTTP Status Message");
}
get body() {
return this._wrapAsValue(this.httpResponse.body, "Raw Response Body");
}
get length() {
return this._wrapAsValue(this.httpResponse.body.length, "Length of Response Body");
}
get headers() {
return this._wrapAsValue(this.httpResponse.headers, "HTTP Headers");
}
get cookies() {
return this._wrapAsValue(this.httpResponse.cookies, "HTTP Cookies");
}
get jsonBody() {
try {
const json = JSON.parse(this.httpResponse.body);
return this._wrapAsValue(json, "JSON Response");
}
catch (ex) {
return this._wrapAsValue(null, `JSON Response: ${ex}`);
}
}
get url() {
return this._wrapAsValue(this.scenario.url, "Request URL");
}
get finalUrl() {
return this._wrapAsValue(this.scenario.finalUrl, "Response URL (after redirects)");
}
get redirectCount() {
return this._wrapAsValue(this.scenario.redirectCount, "Response URL (after redirects)");
}
get loadTime() {
return this._wrapAsValue(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 this._wrapAsValue(typeof headerValue == "undefined" ? null : headerValue, "HTTP Headers[" + key + "]");
}
cookie(key) {
return this._wrapAsValue(this.httpResponse.cookies[key], "HTTP Cookies[" + key + "]");
}
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 this._wrapAsValue(null, selector);
});
}
waitForVisible(selector, timeout = 30000) {
return __awaiter(this, void 0, void 0, function* () {
yield this.context.pause(1);
return this._wrapAsValue(null, selector);
});
}
waitForExists(selector, timeout = 30000) {
return __awaiter(this, void 0, void 0, function* () {
yield this.context.pause(1);
return this._wrapAsValue(null, selector);
});
}
waitForHavingText(selector, text, timeout = 30000) {
return __awaiter(this, void 0, void 0, function* () {
yield this.context.pause(1);
return this._wrapAsValue(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.`);
});
}
_wrapAsValue(data, name, source) {
return new value_1.Value(data, this.context, name, source);
}
}
exports.ProtoResponse = ProtoResponse;
//# sourceMappingURL=response.js.map