@progress/kendo-angular-e2e
Version:
Helper package for Kendo UI for Angular e2e tests
175 lines (174 loc) • 6.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NgBrowser = void 0;
const tslib_1 = require("tslib");
const kendo_e2e_1 = require("@progress/kendo-e2e");
const utils_1 = require("./utils");
const curryWithWebElement = (that, func) => {
return (locator, ...args) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
let el;
if (locator instanceof kendo_e2e_1.By) {
el = yield that.find(locator);
}
else {
el = locator;
}
return func.apply(that, [el, ...args]);
});
};
class NgBrowser extends kendo_e2e_1.Browser {
constructor(baseUrl = 'http://localhost:3000') {
super();
this.hasFocus = curryWithWebElement(this, (el) => {
return super.hasFocus(el);
});
this.expectText = curryWithWebElement(this, (el, text, timeout = 10000) => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.driver.wait(kendo_e2e_1.until.elementTextIs(el, text), timeout, `Element ${yield el.getAttribute('outerHTML')} does not have text - '${text}' after ${timeout} seconds`);
expect(yield el.getText()).toBe(text);
}));
this.expectAttribute = curryWithWebElement(this, (el, attribute, text, timeout = 10000) => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.driver.wait(() => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield el.getAttribute(attribute)) === text; }), timeout, `Element ${yield el.getAttribute('outerHTML')} does not have text - '${text}' after ${timeout} seconds`);
expect(yield el.getAttribute(attribute)).toBe(text);
}));
this.sendCMDCombination = this.sendCTRLCombination;
if (typeof (jasmine) !== 'undefined') {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000;
}
this.baseUrl = baseUrl;
}
navigateTo(url, selectorToWait = 'app-root') {
const _super = Object.create(null, {
navigateTo: { get: () => super.navigateTo }
});
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield _super.navigateTo.call(this, this.baseUrl + url);
yield this.waitForElement(selectorToWait);
return this.sleep(utils_1.DELAYS.SMALL);
});
}
waitForElement(selector, timeout = 10000) {
return this.driver.wait(kendo_e2e_1.until.elementLocated(kendo_e2e_1.By.css(selector)), timeout, `Failed to find element located by ${selector} after ${timeout} ms.`);
}
waitForKendoPopup() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.waitForElement('kendo-popup');
return this.sleep(50);
});
}
resetDemo() {
return this.click(kendo_e2e_1.By.id('reset'));
}
getSize(selector) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let el = yield this.find(kendo_e2e_1.By.css(selector));
return el.getSize();
});
}
arrowUp() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.sendKey(kendo_e2e_1.Key.ARROW_UP);
});
}
arrowDown() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.sendKey(kendo_e2e_1.Key.ARROW_DOWN);
});
}
arrowLeft() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.sendKey(kendo_e2e_1.Key.ARROW_LEFT);
});
}
arrowRight() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.sendKey(kendo_e2e_1.Key.ARROW_RIGHT);
});
}
tab() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.sendKey(kendo_e2e_1.Key.TAB);
});
}
doubleClick(locator) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.driver.actions().
doubleClick(yield this.find(locator))
.perform();
});
}
clickAndHold(origin, x, y, duration) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.driver.actions().
move({ x, y, duration, origin }).
press().perform();
});
}
pointerMove(origin, x, y, duration) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.driver.actions().
move({ x, y, duration, origin }).
perform();
});
}
releaseHold() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield this.driver.actions().
release().
perform();
});
}
getText(locator) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (yield this.find(locator)).getText();
});
}
getAttribute(locator, attribute) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (yield this.find(locator)).getAttribute(attribute);
});
}
sendKeys(locator, text, clear = true) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let el = yield this.find(locator);
if (clear) {
yield el.clear();
}
yield el.sendKeys(text);
});
}
expectValue(locator, text, timeout = 10000) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.expectAttribute(locator, 'value', text, timeout);
});
}
getTextSum(selector) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let elements = yield this.findAll(selector);
let res = "";
for (let element of elements) {
res = res + (yield element.getText());
}
yield this.sleep(utils_1.DELAYS.SM);
return res;
});
}
sendCTRLCombination(...keys) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const capabilities = (yield (yield this.driver).getCapabilities());
const platform = capabilities.getPlatform().toLowerCase().trim();
const ctrlKey = platform.indexOf('mac') === 0 ? kendo_e2e_1.Key.COMMAND : kendo_e2e_1.Key.CONTROL;
const actions = this.driver.actions();
actions.keyDown(ctrlKey);
for (let key of keys) {
actions.keyDown(key);
}
actions.keyUp(ctrlKey);
for (let key of keys) {
actions.keyUp(key);
}
return actions.perform();
});
}
}
exports.NgBrowser = NgBrowser;
NgBrowser.bindings = ['flat', 'data', 'hierarchy'];