UNPKG

@progress/kendo-e2e

Version:

Kendo UI end-to-end test utilities.

237 lines 10.9 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.Table = void 0; const selenium_1 = require("../selenium"); const ui_component_1 = require("./ui-component"); const enums_1 = require("./enums"); const filtermenu_1 = require("./filtermenu"); const columnmenu_1 = require("./columnmenu"); class Table extends ui_component_1.UIComponent { constructor(browser, locator, parentElement) { super(browser, locator, parentElement); this.parentElement = parentElement; } addButton() { return __awaiter(this, void 0, void 0, function* () { return yield this.findChild(Table.TOOLBAR_ADD_BUTTON); }); } saveChanges() { return __awaiter(this, void 0, void 0, function* () { return yield this.findChild(Table.TOOLBAR_SAVE_BUTTON); }); } cancelChanges() { return __awaiter(this, void 0, void 0, function* () { return yield this.findChild(Table.TOOLBAR_CANCEL_BUTTON); }); } headerByIndex(column) { return __awaiter(this, void 0, void 0, function* () { const locator = `thead tr th:nth-of-type(${column})`; return yield this.findChild(locator); }); } headerByText(text_1) { return __awaiter(this, arguments, void 0, function* (text, { exactMatch = true } = {}) { const locator = exactMatch ? selenium_1.By.xpath(`.//thead//tr//th[.='${text}']`) : selenium_1.By.xpath(`.//thead//tr//th[contains(., '${text}')]`); return yield this.findChild(locator); }); } columnMenuByIndex(column) { return __awaiter(this, void 0, void 0, function* () { const locator = `thead tr th:nth-of-type(${column}) .k-grid-column-menu`; return yield this.findChild(locator); }); } columnMenuByText(text_1) { return __awaiter(this, arguments, void 0, function* (text, { exactMatch = true } = {}) { const locator = exactMatch ? selenium_1.By.xpath(`.//thead//tr//th[.='${text}']//*[contains(@class, 'k-grid-column-menu')]`) : selenium_1.By.xpath(`.//thead//tr//th[contains(., '${text}')]//*[contains(@class, 'k-grid-column-menu')]`); return yield this.findChild(locator); }); } filterMenuByIndex(column) { return __awaiter(this, void 0, void 0, function* () { const locator = `thead tr th:nth-of-type(${column}) .k-grid-filter-menu`; return yield this.findChild(locator); }); } filterMenuByText(text_1) { return __awaiter(this, arguments, void 0, function* (text, { exactMatch = true } = {}) { const locator = exactMatch ? selenium_1.By.xpath(`.//thead//tr/*[.='${text}']//*[contains(@class, 'k-grid-filter-menu')]`) : selenium_1.By.xpath(`.//thead//tr/*[contains(., '${text}')]//*[contains(@class, 'k-grid-filter-menu')]`); return yield this.findChild(locator); }); } headerSortType(text_1) { return __awaiter(this, arguments, void 0, function* (text, { exactMatch = true } = {}) { const header = yield this.headerByText(text, { exactMatch: exactMatch }); if ((yield header.findElements(selenium_1.By.css(".k-svg-i-sort-asc-small"))).length > 0) { return enums_1.SortType.Asc; } if ((yield header.findElements(selenium_1.By.css(".k-svg-i-sort-desc-small"))).length > 0) { return enums_1.SortType.Desc; } else { return enums_1.SortType.None; } }); } filterInput(column) { return __awaiter(this, void 0, void 0, function* () { const angular = `.k-filter-row td:nth-of-type(${column}) input.k-input`; const jqueryTH = `.k-filter-row th:nth-of-type(${column}) input.k-input-inner`; const jqueryTD = `.k-filter-row td:nth-of-type(${column}) input.k-input-inner`; return yield this.browser.findChild(yield this.root(), `${angular},${jqueryTH},${jqueryTD}`); }); } openColumnMenu(text) { return __awaiter(this, void 0, void 0, function* () { const button = yield this.columnMenuByText(text); yield this.browser.waitForAnimationAndClick(button); const popup = yield this.browser.find('.k-animation-container-shown'); yield this.browser.waitForAnimation('.k-animation-container-shown .k-column-menu'); return new columnmenu_1.ColumnMenu(this.browser, '.k-column-menu', popup); }); } openFilterMenu(text) { return __awaiter(this, void 0, void 0, function* () { const button = yield this.filterMenuByText(text); yield button.click(); const popup = yield this.browser.find('.k-animation-container-shown form'); yield this.browser.waitForAnimation('.k-animation-container-shown form .k-filter-menu-container'); return new filtermenu_1.FilterMenu(this.browser, '.k-filter-menu-container', popup); }); } tableRows() { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChildren(yield this.root(), "tbody > tr", { waitForChild: false }); }); } tableRow(index) { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChild(yield this.root(), `tbody > tr:nth-of-type(${index})`); }); } tableRowsCount() { return __awaiter(this, arguments, void 0, function* ({ onlyVisible = false } = {}) { const rows = yield this.tableRows(); if (onlyVisible) { let count = 0; for (const row of rows) { if (yield row.isDisplayed()) { count++; } } return count; } else { return rows.length; } }); } waitForRows(rowsCount_1) { return __awaiter(this, arguments, void 0, function* (rowsCount, { timeout = 10000, pollTimeout = 100 } = {}) { yield this.browser.wait(() => __awaiter(this, void 0, void 0, function* () { return (yield this.tableRowsCount()) === rowsCount; }), { timeout: timeout, pollTimeout: pollTimeout, message: `Expected table to have ${rowsCount} rows, but actual rows are ${yield this.tableRowsCount()}.`, }); }); } cellLocator(row, column) { return `tbody > tr:nth-of-type(${row}) > td[role='gridcell']:nth-of-type(${column})`; } cell(row, column) { return __awaiter(this, void 0, void 0, function* () { return yield this.findChild(this.cellLocator(row, column)); }); } cellText(row, column) { return __awaiter(this, void 0, void 0, function* () { try { return yield (yield this.cell(row, column)).getText(); } catch (_a) { return undefined; } }); } cellInput(row, column) { return __awaiter(this, void 0, void 0, function* () { const locator = `${this.cellLocator(row, column)} input:not([style*="none"])`; return yield this.findChild(locator); }); } writeInCell(row_1, column_1, text_1) { return __awaiter(this, arguments, void 0, function* (row, column, text, { clickToFocus = true, clear = true, sendEnter = false } = {}) { const input = `${this.cellLocator(row, column)} input:not([style*="none"])`; if (clickToFocus) { yield this.browser.click(this.cellLocator(row, column)); yield this.browser.wait(selenium_1.EC.isVisible(input), { timeout: 3000, message: 'Failed to show input on cell click.' }); } if (clear) { yield this.browser.sendControlKeyCombination("a"); yield this.browser.sleep(10); yield this.browser.sendKey(selenium_1.Key.BACK_SPACE); yield this.browser.sleep(10); } yield this.browser.sendKey(text); yield this.browser.sleep(10); if (sendEnter) { yield this.browser.sendKey(selenium_1.Key.ENTER); } }); } dragCellByRow(index) { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChild(yield this.root(), `tbody > tr:nth-of-type(${index}) td[aria-label="Drag row"]`); }); } addCommandByRow(index) { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChild(yield this.root(), `tbody > tr:nth-of-type(${index}) .k-grid-add`); }); } editCommandByRow(index) { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChild(yield this.root(), `tbody > tr:nth-of-type(${index}) .k-grid-edit-command`); }); } removeCommandByRow(index) { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChild(yield this.root(), selenium_1.By.css(`tbody > tr:nth-of-type(${index}) .k-grid-remove-command`)); }); } saveCommandByRow(index) { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChild(yield this.root(), `tbody > tr:nth-of-type(${index}) .k-grid-save-command`); }); } cancelCommandByRow(index) { return __awaiter(this, void 0, void 0, function* () { return yield this.browser.findChild(yield this.root(), `tbody > tr:nth-of-type(${index}) .k-grid-cancel-command`); }); } } exports.Table = Table; Table.TOOLBAR_ADD_BUTTON = ".k-grid-add, .k-grid-add-command"; Table.TOOLBAR_SAVE_BUTTON = ".k-grid-save-changes"; Table.TOOLBAR_CANCEL_BUTTON = ".k-grid-cancel-changes"; //# sourceMappingURL=table.js.map