flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
111 lines • 5.29 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 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) {
yield context.assert('DOM Ready', context.waitForNavigation(3000, 'domcontentloaded')).resolves();
const extExists = `!!Ext`;
yield context.page.waitForFunction(extExists);
yield context.assert('Found Ext object.', yield context.page.evaluate(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]/ig, '')}`;
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 null;
}
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]/ig, '')}`;
const queryToInject = `window.${componentReference} = Ext.ComponentQuery.query("${path}");`;
yield this.page.addScriptTag({ content: queryToInject });
const length = 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 = name => super[name];
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 !== null) {
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 !== null) {
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