flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
120 lines • 5.61 kB
JavaScript
;
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 extjscomponent_1 = require("./extjscomponent");
const enums_1 = require("./enums");
const puppeteerresponse_1 = require("./puppeteerresponse");
class ExtJSResponse extends puppeteerresponse_1.PuppeteerResponse {
get responseTypeName() {
return "ExtJS";
}
get responseType() {
return enums_1.ResponseType.extjs;
}
constructor(scenario) {
super(scenario);
scenario.before(() => {
scenario.nextPrepend((context) => __awaiter(this, void 0, void 0, function* () {
if (context.page !== null) {
const extExists = yield context.evaluate(function () {
return !!window["Ext"];
});
context.assert("ExtJS was found.", extExists).equals(true);
return context
.assert("Ext.onReady fired", context.waitForReady(15000))
.resolves();
}
}));
});
}
find(path) {
return __awaiter(this, void 0, void 0, function* () {
if (this.page !== null) {
const componentReference = `flagpole_${Date.now()}_${path.replace(/[^a-z]/gi, "")}`;
path = path.replace(/\'/g, "\\'");
path = path.replace(/\"/g, '\\"');
const queryToInject = `window.${componentReference} = Ext.ComponentQuery.query("${path}")[0];`;
yield this.page.addScriptTag({ content: queryToInject });
const exists = !!(yield this.page.evaluate(`!!window.${componentReference}`));
if (exists) {
return yield extjscomponent_1.ExtJsComponent.create(componentReference, this.context, `${path}[0]`);
}
return this._wrapAsValue(null, path);
}
throw new Error("Cannot evaluate code becuase page is null.");
});
}
findAll(path) {
return __awaiter(this, void 0, void 0, function* () {
if (this.page !== null) {
const componentReference = `flagpole_${Date.now()}_${path.replace(/[^a-z]/gi, "")}`;
const queryToInject = `window.${componentReference} = Ext.ComponentQuery.query("${path}");`;
yield this.page.addScriptTag({ content: queryToInject });
const length = Number(yield this.page.evaluate(`window.${componentReference}.length`));
let components = [];
for (let i = 0; i < length; i++) {
components.push(yield extjscomponent_1.ExtJsComponent.create(`window.${componentReference}[${i}]`, this.context, `${path}[${i}]`));
}
return components;
}
throw new Error("Cannot evaluate code becuase page is null.");
});
}
waitForReady(timeout = 15000) {
const _super = Object.create(null, {
waitForReady: { get: () => super.waitForReady }
});
return __awaiter(this, void 0, void 0, function* () {
if (this.page !== null) {
yield this.page.evaluate(`Ext.onReady(() => { window.flagpoleExtReady = true; });`);
yield this.page.waitForFunction(`window.flagpoleExtReady`, {
timeout: timeout
});
return;
}
return _super.waitForReady.call(this, timeout);
});
}
type(selector, textToType, opts = {}) {
return __awaiter(this, void 0, void 0, function* () {
if (this.page !== null) {
const component = yield this.find(selector);
if (component instanceof extjscomponent_1.ExtJsComponent) {
component.fireEvent("focus");
component.setValue(textToType);
component.fireEvent("blur");
}
else {
throw new Error(`Could not find component at ${selector}`);
}
}
throw new Error(`Can not type into element ${selector}`);
});
}
clear(selector) {
return __awaiter(this, void 0, void 0, function* () {
if (this.page !== null) {
const component = yield this.find(selector);
if (component instanceof extjscomponent_1.ExtJsComponent) {
component.fireEvent("focus");
component.setValue("");
component.fireEvent("blur");
}
else {
throw new Error(`Could not find component at ${selector}`);
}
}
throw new Error(`Can not type into this element ${selector}`);
});
}
}
exports.ExtJSResponse = ExtJSResponse;
//# sourceMappingURL=extjsresponse.js.map