@progress/kendo-e2e
Version:
Kendo UI end-to-end test utilities.
207 lines • 8.43 kB
JavaScript
"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.DropDown = void 0;
const selenium_1 = require("../selenium");
const const_1 = require("./const");
const ui_component_1 = require("./ui-component");
class DropDown extends ui_component_1.UIComponent {
constructor(browser, locator, rootElement) {
super(browser, locator, rootElement);
}
popupSelector() {
return __awaiter(this, void 0, void 0, function* () {
let id;
const rootAriaControls = yield (yield this.root()).getAttribute("aria-controls");
if (rootAriaControls !== null) {
id = rootAriaControls.split("_")[0];
}
else {
const childAriaControls = yield this.findChild("[aria-controls]");
id = (yield childAriaControls.getAttribute("aria-controls")).split("_")[0];
}
if (id.length > 1) {
return selenium_1.By.xpath(`//div[contains(@class, "k-animation-container-shown")]//div[contains(@id, "${id}")]/../..//*[contains(@class, "k-popup") and not(contains(@style, "none"))]`);
}
else {
throw new Error('Failed to get aria-controls value.');
}
});
}
popup() {
return __awaiter(this, void 0, void 0, function* () {
const popup = yield this.popupSelector();
return yield this.browser.find(popup);
});
}
isPopupShown() {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.browser.findAll(yield this.popupSelector())).length > 0;
});
}
input() {
return __awaiter(this, void 0, void 0, function* () {
return this.findChild(DropDown.INPUT);
});
}
clear() {
return __awaiter(this, void 0, void 0, function* () {
return this.findChild(DropDown.CLEAR_VALUE);
});
}
clearValue() {
return __awaiter(this, void 0, void 0, function* () {
yield (yield this.clear()).click();
});
}
getChips() {
return __awaiter(this, arguments, void 0, function* ({ waitForChip = true } = {}) {
return this.findChildren(const_1.SELECTORS.CHIP, { waitForChild: waitForChip });
});
}
select() {
return __awaiter(this, void 0, void 0, function* () {
return this.findChild(DropDown.SELECT);
});
}
expand() {
return __awaiter(this, void 0, void 0, function* () {
let expander;
const root = yield this.root();
const cssClass = yield root.getAttribute('class');
const isDropDownButton = cssClass.includes('k-dropdown-button');
const isMultiSelect = cssClass.includes('k-multiselect');
const isMultiSelectable = (yield root.getAttribute("aria-multiselectable")) === "true";
if (isDropDownButton || isMultiSelect || isMultiSelectable) {
expander = root;
}
else {
expander = yield this.select();
}
try {
yield expander.click();
}
catch (e) {
if (e.name === 'ElementClickInterceptedError') {
yield this.browser.sleep(500);
yield expander.click();
}
}
yield this.waitToExpand();
});
}
waitToExpand() {
return __awaiter(this, void 0, void 0, function* () {
const popup = yield this.popupSelector();
yield this.browser.wait(selenium_1.EC.isVisible(popup), { timeout: 5000, message: "Failed to expand popup." });
yield this.browser.waitForAnimation(popup, { timeout: 3000, pollTimeout: 50 });
});
}
waitToCollapse() {
return __awaiter(this, void 0, void 0, function* () {
const popup = yield this.popupSelector();
yield this.browser.wait(selenium_1.EC.notVisible(popup), { timeout: 5000, message: "Failed to collapse popup." });
yield this.browser.sleep(100); // Wait for animation timeout
});
}
getText() {
return __awaiter(this, void 0, void 0, function* () {
return yield (yield this.root()).getText();
});
}
getValue() {
return __awaiter(this, void 0, void 0, function* () {
const input = yield this.input();
return yield input.getAttribute("value");
});
}
getItems() {
return __awaiter(this, arguments, void 0, function* ({ waitForItems = true } = {}) {
return yield this.browser.findChildren(yield this.popupSelector(), "li", { waitForChild: waitForItems });
});
}
getSelectedItem() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.browser.findChild(yield this.popupSelector(), "li.k-selected");
});
}
getFocusedItem() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.browser.findChild(yield this.popupSelector(), "li.k-focus");
});
}
getItemByIndex(index) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.browser.findChildren(yield this.popupSelector(), "li"))[index];
});
}
getItemByText(text) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.browser.findChild(yield this.popupSelector(), selenium_1.By.xpath(`.//li[.="${text}"]`));
});
}
selectItemByIndex(index_1) {
return __awaiter(this, arguments, void 0, function* (index, { expand = true, waitToCollapse = true } = {}) {
if (expand) {
yield this.expand();
}
yield (yield this.getItemByIndex(index)).click();
if (waitToCollapse) {
yield this.waitToCollapse();
}
});
}
selectItemByText(text_1) {
return __awaiter(this, arguments, void 0, function* (text, { expand = true, waitToCollapse = true } = {}) {
if (expand) {
yield this.expand();
}
try {
yield (yield this.getItemByText(text)).click();
}
catch (e) {
if (e.name === 'StaleElementReferenceError') {
yield this.browser.sleep(500);
yield (yield this.getItemByText(text)).click();
}
}
if (waitToCollapse) {
yield this.waitToCollapse();
}
});
}
isPopupEmpty() {
return __awaiter(this, void 0, void 0, function* () {
const popup = yield this.popup();
const noDateItems = yield popup.findElements(selenium_1.By.css(".k-no-data"));
if (noDateItems.length > 0) {
return noDateItems[0].isDisplayed();
}
else {
return false;
}
});
}
isEnabled() {
return __awaiter(this, void 0, void 0, function* () {
const rootClass = yield (yield this.root()).getAttribute("class");
const input = yield this.browser.findChild(yield this.root(), "input");
const isVisuallyEnabled = !rootClass.includes(const_1.STATES.DISABLED);
const isKeyboardEnabled = yield input.isEnabled();
return isVisuallyEnabled && isKeyboardEnabled;
});
}
}
exports.DropDown = DropDown;
DropDown.INPUT = ".k-input-inner";
DropDown.CLEAR_VALUE = ".k-clear-value";
DropDown.SELECT = ".k-input-button";
//# sourceMappingURL=dropdown.js.map