UNPKG

@redhat-developer/page-objects

Version:

Page Object API implementation for a VS Code editor used by ExTester framework.

139 lines 4.72 kB
"use strict"; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License", destination); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextMenuItem = exports.ContextMenu = void 0; const __1 = require("../.."); const selenium_webdriver_1 = require("selenium-webdriver"); /** * Object representing a context menu */ class ContextMenu extends __1.Menu { constructor(containingElement) { super(ContextMenu.locators.ContextMenu.constructor, containingElement); } /** * Get context menu item by name * @param name name of the item to search by * @returns Promise resolving to ContextMenuItem object */ async getItem(name) { try { const items = await this.getItems(); for (const item of items) { if ((await item.getLabel()) === name) { return item; } } } catch (err) { return undefined; } } /** * Get all context menu items * @returns Promise resolving to array of ContextMenuItem objects */ async getItems() { const items = []; const elements = await this.findElements(ContextMenu.locators.ContextMenu.itemElement); for (const element of elements) { const klass = await element.getAttribute('class'); if (klass.indexOf('disabled') < 0) { items.push(await new ContextMenuItem(element, this).wait()); } } return items; } /** * Close the context menu * @returns Promise resolving when the menu is closed */ async close() { const actions = this.getDriver().actions(); await actions.clear(); await this.getDriver().actions().sendKeys(selenium_webdriver_1.Key.ESCAPE).perform(); try { await this.getDriver().wait(selenium_webdriver_1.until.elementIsNotVisible(this)); } catch (err) { if (!(err instanceof selenium_webdriver_1.error.StaleElementReferenceError)) { throw err; } } } /** * Wait for the menu to appear and load all its items */ async wait(timeout = 5000) { await this.getDriver().wait(selenium_webdriver_1.until.elementIsVisible(this), timeout); let items = (await this.getItems()).length; try { await this.getDriver().wait(async () => { const temp = (await this.getItems()).length; if (temp === items) { return true; } else { items = temp; return false; } }, 1000); } catch (err) { if (err instanceof selenium_webdriver_1.error.TimeoutError) { // ignore timeout } else { throw err; } } return this; } } exports.ContextMenu = ContextMenu; /** * Object representing an item of a context menu */ class ContextMenuItem extends __1.MenuItem { constructor(item, parent) { super(item, parent); this.parent = parent; } async select() { await this.click(); await new Promise((res) => setTimeout(res, 500)); if (await this.isNesting()) { return await new ContextMenu(this).wait(); } return undefined; } async getLabel() { const labelItem = await this.findElement(ContextMenu.locators.ContextMenu.itemLabel); return await labelItem.getAttribute(ContextMenu.locators.ContextMenu.itemText); } async isNesting() { try { return await this.findElement(ContextMenu.locators.ContextMenu.itemNesting).isDisplayed(); } catch (err) { return false; } } } exports.ContextMenuItem = ContextMenuItem; //# sourceMappingURL=ContextMenu.js.map