UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

299 lines 11.2 kB
"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 }); exports.ExtJsComponent = exports.ExtJsComponentTypes = void 0; const puppeteerelement_1 = require("./puppeteerelement"); const util_1 = require("./util"); exports.ExtJsComponentTypes = { actionsheet: "Ext.ActionSheet", audio: "Ext.Audio", button: "Ext.Button", image: "Ext.Img", label: "Ext.Label", loadmask: "Ext.LoadMask", panel: "Ext.Panel", segmentedbutton: "Ext.SegmentedButton", sheet: "Ext.Sheet", spacer: "Ext.Spacer", titlebar: "Ext.TitleBar", toolbar: "Ext.Toolbar", video: "Ext.Video", carousel: "Ext.carousel.Carousel", navigationview: "Ext.navigation.View", datepicker: "Ext.picker.Date", picker: "Ext.picker.Picker", slider: "Ext.slider.Slider", thumb: "Ext.slider.Thumb", tabpanel: "Ext.tab.Panel", viewport: "Ext.viewport.Default", dataview: "Ext.dataview.DataView", list: "Ext.dataview.List", nestedlist: "Ext.dataview.NestedList", checkboxfield: "Ext.field.Checkbox", datepickerfield: "Ext.field.DatePicker", emailfield: "Ext.field.Email", hiddenfield: "Ext.field.Hidden", numberfield: "Ext.field.Number", passwordfield: "Ext.field.Password", radiofield: "Ext.field.Radio", searchfield: "Ext.field.Search", selectfield: "Ext.field.Select", sliderfield: "Ext.field.Slider", spinnerfield: "Ext.field.Spinner", textfield: "Ext.field.Text", textareafield: "Ext.field.TextArea", togglefield: "Ext.field.Toggle", treelist: "Ext.list.Tree", urlfield: "Ext.field.Url", fieldset: "Ext.form.FieldSet", formpanel: "Ext.form.Panel", }; class ExtJsComponent extends puppeteerelement_1.PuppeteerElement { constructor(handle, context, name, path) { super(handle, context, name, path || name); this._path = path || name; this._input = handle; } get $() { return this._input; } get path() { return this._path; } get name() { return this._name || this._path || "ExtJs Component"; } get _response() { return this._context.response; } get _isExtComponent() { return this.toType() == "ext"; } static create(handle, context, name, path) { return __awaiter(this, void 0, void 0, function* () { const element = new ExtJsComponent(handle, context, name, path); const componentType = yield element._getTagName(); if (componentType !== null) { element._name = `<${componentType}> Component @ ${element.path}`; } return element; }); } focus() { return __awaiter(this, void 0, void 0, function* () { return this._action("focus"); }); } hover() { return __awaiter(this, void 0, void 0, function* () { return this._action("hover"); }); } blur() { return __awaiter(this, void 0, void 0, function* () { return this._action("blur"); }); } click() { return __awaiter(this, void 0, void 0, function* () { return this._action("click"); }); } find(selector) { return __awaiter(this, void 0, void 0, function* () { throw "component.find is not yet implemented in Ext"; }); } findAll(selector) { return __awaiter(this, void 0, void 0, function* () { throw "component.findAll is not yet implemented in Ext"; }); } clear() { return __awaiter(this, void 0, void 0, function* () { yield this.setValue(""); this._completedAction("CLEAR"); }); } type(textToType, opts) { return __awaiter(this, void 0, void 0, function* () { yield this.focus(); yield this.setValue(textToType); this._completedAction("TYPE", (yield this.isPasswordField()) ? textToType.replace(/./g, "*") : textToType); return this.blur(); }); } pressEnter() { return __awaiter(this, void 0, void 0, function* () { return this._action("action"); }); } setValue(text) { return this.eval((c, text) => c.setValue(text), text); } getParent() { return __awaiter(this, void 0, void 0, function* () { const id = String(yield this.eval((c) => c.parent.id)); const component = yield this._response.getComponentById(id); return component || this._wrapAsValue(null, `Parent of ${this.name}`); }); } getNextSibling(selector) { return __awaiter(this, void 0, void 0, function* () { const id = String(yield this.eval((c) => c.nextSibling(selector))); const component = yield this._response.getComponentById(id); return component || this._wrapAsValue(null, `Next Sibling of ${this.name}`); }); } getPreviousSibling(selector) { return __awaiter(this, void 0, void 0, function* () { const id = String(yield this.eval((c) => c.previousSibling(selector))); const component = yield this._response.getComponentById(id); return (component || this._wrapAsValue(null, `Previous Sibling of ${this.name}`)); }); } eval(js, ...args) { return __awaiter(this, void 0, void 0, function* () { return this.$.evaluate.apply(this.$, [js, ...args]); }); } getClosest(selector = "[data-componentid]") { const _super = Object.create(null, { getClosest: { get: () => super.getClosest } }); return __awaiter(this, void 0, void 0, function* () { if (this._isExtComponent && selector == "[data-componentid]") { return this; } return _super.getClosest.call(this, selector); }); } selectOption(valuesToSelect) { return __awaiter(this, void 0, void 0, function* () { valuesToSelect = util_1.arrayify(valuesToSelect); this._completedAction("SELECT", valuesToSelect.join(", ")); const ableToSetValue = yield this.eval((c, valuesToSelect) => { let value = ""; const displayField = c.getDisplayField(); const valueField = c.getValueField(); const searchValue = valuesToSelect[0]; const store = c.getStore(); const valueResult = store.queryBy(valueField, searchValue); if (valueResult && valueResult.indices) { value = Object.keys(valueResult.indices)[0]; } if (!value.length) { const displayResult = store.queryBy(displayField, searchValue); if (displayResult && displayResult.indices) { value = Object.keys(displayResult.indices)[0]; } } if (value.length) { c.setValue(value); return true; } return false; }, valuesToSelect); this._context .assert(`Select values on ${this.name}`, ableToSetValue) .equals(true); }); } scrollTo() { return __awaiter(this, void 0, void 0, function* () { this.eval((c) => c.element.dom.scrollIntoView()); }); } _action(eventName) { return __awaiter(this, void 0, void 0, function* () { eventName = eventName.toLowerCase(); yield this.eval((c, eventName) => { c[eventName] && c[eventName](); c.element && c.element[eventName] && c.element[eventName](); c.element.dom && c.element.dom[eventName] && c.element.dom[eventName](); c.fireEvent(eventName); }, eventName); this._completedAction(eventName.toUpperCase()); }); } _getClassName() { return __awaiter(this, void 0, void 0, function* () { return String(yield this.eval((c) => c.element.dom.className)); }); } _getAttribute(key) { return this.eval((c) => c.element.getAttribute(key)); } _getTagName() { return __awaiter(this, void 0, void 0, function* () { this._tagName = String(yield this.eval((c) => c.xtype)); return this._tagName; }); } _getInnerText() { return __awaiter(this, void 0, void 0, function* () { return String(yield this.eval((c) => c.element.dom.innerText)); }); } _getInnerHtml() { return __awaiter(this, void 0, void 0, function* () { return String(yield this.eval((c) => c.element.dom.innerHTML)); }); } _getOuterHtml() { return __awaiter(this, void 0, void 0, function* () { return String(yield this.eval((c) => c.element.dom.outerHTML)); }); } _getText() { return __awaiter(this, void 0, void 0, function* () { const result = yield this.eval((c) => { var _a, _b; if (c.getText) { return c.getText(); } if ((_b = (_a = c.element) === null || _a === void 0 ? void 0 : _a.dom) === null || _b === void 0 ? void 0 : _b.innerText) { return c.element.dom.innerText; } if (c.getLabel) { return c.getLabel(); } if (c.getTitle) { return c.getTitle(); } if (c.getDisplayValue) { return c.getDisplayValue(); } return ""; }); return String(result); }); } _getValue() { return __awaiter(this, void 0, void 0, function* () { return this.eval((c) => c.getValue()); }); } _getData(key) { return __awaiter(this, void 0, void 0, function* () { return this.eval((c) => c.getData(key)); }); } isPasswordField() { return __awaiter(this, void 0, void 0, function* () { return this.eval((c) => c.inputElement.dom.getAttribute("type") == "password"); }); } } exports.ExtJsComponent = ExtJsComponent; //# sourceMappingURL=extjscomponent.js.map