flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
116 lines • 4.4 kB
JavaScript
"use strict";
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 value_1 = require("./value");
class Element extends value_1.ProtoValue {
hasClass(className) {
return __awaiter(this, void 0, void 0, function* () {
if (this.isCheerioElement()) {
return this._input.hasClass(className);
}
else if (this.isPuppeteerElement()) {
const classHandle = yield this._input.getProperty('className');
const classString = yield classHandle.jsonValue();
return (classString.split(' ').indexOf(className) >= 0);
}
return false;
});
}
getTagName() {
return __awaiter(this, void 0, void 0, function* () {
if (this.isCheerioElement()) {
return this._input.get(0).tagName;
}
return null;
});
}
getAttribute(key) {
return __awaiter(this, void 0, void 0, function* () {
if (this.isCheerioElement()) {
return (typeof this._input.get(0).attribs[name] !== 'undefined') ?
this._input.get(0).attribs[name] : null;
}
else if (this.isPuppeteerElement()) {
const handle = yield this._input.getProperty(key);
return yield handle.jsonValue();
}
else if (!this.isNullOrUndefined() && this.hasProperty(key)) {
return this._input[key];
}
return null;
});
}
getProperty(key) {
return __awaiter(this, void 0, void 0, function* () {
let text;
if (this.isCheerioElement()) {
return this._input.prop(key);
}
else if (this.isPuppeteerElement()) {
const handle = yield this._input.getProperty(key);
return yield handle.jsonValue();
}
else if (!this.isNullOrUndefined() && this.hasProperty(key)) {
return this._input[key];
}
return null;
});
}
getData(key) {
return __awaiter(this, void 0, void 0, function* () {
let text;
if (this.isCheerioElement()) {
return this._input.data(key);
}
else if (this.isPuppeteerElement()) {
const handle = yield this._input.getProperty(key);
return yield handle.jsonValue();
}
else if (!this.isNullOrUndefined() && this.hasProperty(key)) {
return this._input[key];
}
return null;
});
}
getValue() {
return __awaiter(this, void 0, void 0, function* () {
let text;
if (this.isCheerioElement()) {
return this._input.val();
}
else if (this.isPuppeteerElement()) {
const handle = yield this._input.getProperty('value');
return yield handle.jsonValue();
}
else if (!this.isNullOrUndefined()) {
return this._input;
}
return null;
});
}
getText() {
return __awaiter(this, void 0, void 0, function* () {
let text;
if (this.isCheerioElement()) {
return this._input.text();
}
else if (this.isPuppeteerElement()) {
const handle = yield this._input.getProperty('textContent');
return yield handle.jsonValue();
}
else if (!this.isNullOrUndefined()) {
return this._input;
}
return null;
});
}
}
exports.Element = Element;
//# sourceMappingURL=element.js.map