UNPKG

@redhat-developer/page-objects

Version:

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

195 lines 8.34 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.ViewPanelActionDropdown = exports.ViewPanelAction = exports.ViewSection = void 0; const selenium_webdriver_1 = require("selenium-webdriver"); const __1 = require("../.."); const AbstractElement_1 = require("../AbstractElement"); const ElementWithContextMenu_1 = require("../ElementWithContextMenu"); const ActionButtonElementDropdown_1 = require("../ActionButtonElementDropdown"); /** * Page object representing a collapsible content section of the side bar view */ class ViewSection extends AbstractElement_1.AbstractElement { constructor(panel, content) { super(panel, content); } /** * Get the title of the section as string * @returns Promise resolving to section title */ async getTitle() { const title = await this.findElement(ViewSection.locators.ViewSection.title); return await title.getAttribute(ViewSection.locators.ViewSection.titleText); } /** * Expand the section if collapsed * @returns Promise resolving when the section is expanded */ async expand(timeout = 1_000) { if (await this.isHeaderHidden()) { return; } if (!(await this.isExpanded())) { const header = await this.findElement(ViewSection.locators.ViewSection.header); const collapseExpandButton = await header.findElement(ViewSection.locators.ViewSection.headerCollapseExpandButton); await collapseExpandButton.click(); await this.getDriver().wait((0, __1.waitForAttributeValue)(header, ViewSection.locators.ViewSection.headerExpanded, 'true'), timeout); await this.getDriver().sleep(500); } } /** * Collapse the section if expanded * @returns Promise resolving when the section is collapsed */ async collapse(timeout = 1_000) { if (await this.isHeaderHidden()) { return; } if (await this.isExpanded()) { const header = await this.findElement(ViewSection.locators.ViewSection.header); const collapseExpandButton = await header.findElement(ViewSection.locators.ViewSection.headerCollapseExpandButton); await collapseExpandButton.click(); await this.getDriver().wait((0, __1.waitForAttributeValue)(header, ViewSection.locators.ViewSection.headerExpanded, 'false'), timeout); await this.getDriver().sleep(500); } } /** * Finds whether the section is expanded * @returns Promise resolving to true/false */ async isExpanded() { const header = await this.findElement(ViewSection.locators.ViewSection.header); const expanded = await header.getAttribute(ViewSection.locators.ViewSection.headerExpanded); return expanded === 'true'; } /** * Finds [Welcome Content](https://code.visualstudio.com/api/extension-guides/tree-view#welcome-content) * present in this ViewSection and returns it. If none is found, then `undefined` is returned * */ async findWelcomeContent() { try { const res = await this.findElement(ViewSection.locators.ViewSection.welcomeContent); if (!(await res.isDisplayed())) { return undefined; } return new __1.WelcomeContentSection(res, this); } catch (_err) { return undefined; } } /** * Retrieve the action buttons on the section's header * @returns Promise resolving to array of ViewPanelAction objects */ async getActions() { const actions = await this.findElement(ViewSection.locators.ViewSection.actions).findElements(ViewSection.locators.ViewSection.button); return Promise.all(actions.map(async (action) => { const dropdown = await action.getAttribute('aria-haspopup'); if (dropdown) { return new ViewPanelActionDropdown(action, this); } else { return new ViewPanelAction(action, this); } })); } /** * Retrieve an action button on the sections's header by its label * @param label label/title of the button * @returns ViewPanelAction object if found, undefined otherwise */ async getAction(label) { const actions = await this.getActions(); for (const action of actions) { if ((await action.getLabel()) === label) { return action; } } } /** * Click on the More Actions... item if it exists * * @returns ContextMenu page object if the action succeeds, undefined otherwise */ async moreActions() { const more = await this.getAction('More Actions...'); if (!more) { return undefined; } const section = this; const btn = new (class extends ElementWithContextMenu_1.ElementWithContextMenu { async openContextMenu() { await this.click(); const shadowRootHost = await section.findElements(ViewSection.locators.ViewSection.shadowRootHost); if (shadowRootHost.length > 0) { let shadowRoot; const webdriverCapabilities = await this.getDriver().getCapabilities(); const chromiumVersion = webdriverCapabilities.getBrowserVersion(); if (chromiumVersion && parseInt(chromiumVersion.split('.')[0]) >= 96) { shadowRoot = await shadowRootHost[0].getShadowRoot(); return new __1.ContextMenu(await shadowRoot.findElement(ViewSection.locators.ViewSection.monacoMenuContainer)).wait(); } else { shadowRoot = (await this.getDriver().executeScript('return arguments[0].shadowRoot', shadowRootHost[0])); return new __1.ContextMenu(shadowRoot).wait(); } } return await super.openContextMenu(); } })(more, this); return await btn.openContextMenu(); } async isHeaderHidden() { const header = await this.findElement(ViewSection.locators.ViewSection.header); return (await header.getAttribute('class')).indexOf('hidden') > -1; } } exports.ViewSection = ViewSection; /** * Base class for action buttons on view sections. * Provides shared functionality for both standard and dropdown actions. */ class BaseViewPanelAction extends ActionButtonElementDropdown_1.ActionButtonElementDropdown { constructor(element, viewPart) { super(element, viewPart); } /** * Get label of the action button */ async getLabel() { return await this.getAttribute(BaseViewPanelAction.locators.ViewSection.buttonLabel); } /** * Wait for the action button to be located within a given timeout. * @param timeout Time in milliseconds (default: 1000ms) */ async wait(timeout = 1_000) { await this.getDriver().wait(selenium_webdriver_1.until.elementLocated(BaseViewPanelAction.locators.ViewSection.actions), timeout); return this; } } class ViewPanelAction extends BaseViewPanelAction { } exports.ViewPanelAction = ViewPanelAction; class ViewPanelActionDropdown extends BaseViewPanelAction { } exports.ViewPanelActionDropdown = ViewPanelActionDropdown; //# sourceMappingURL=ViewSection.js.map