flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
65 lines • 2.42 kB
JavaScript
;
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");
const domelement_1 = require("./domelement");
let cheerio = require('cheerio');
let $;
class HtmlResponse extends response_1.GenericResponse {
get typeName() {
return 'HTML';
}
get type() {
return response_1.ResponseType.html;
}
constructor(scenario, response) {
super(scenario, response);
$ = cheerio.load(response.body);
}
getRoot() {
return $;
}
evaluate(context, callback) {
return __awaiter(this, void 0, void 0, function* () {
return callback.apply(context, [$]);
});
}
find(path) {
return __awaiter(this, void 0, void 0, function* () {
const selection = $(path);
if (selection.length > 0) {
return yield domelement_1.DOMElement.create(selection.eq(0), this.context, null, path);
}
else {
return null;
}
});
}
findAll(path) {
return __awaiter(this, void 0, void 0, function* () {
const response = this;
const elements = $(path);
if (elements.length > 0) {
const nodeElements = [];
yield elements.each(function (i) {
return __awaiter(this, void 0, void 0, function* () {
nodeElements.push(yield domelement_1.DOMElement.create($(elements.get(i)), response.context, `${path} [${i}]`, path));
});
});
return nodeElements;
}
else {
return [];
}
});
}
}
exports.HtmlResponse = HtmlResponse;
//# sourceMappingURL=htmlresponse.js.map