UNPKG

@redhat-developer/page-objects

Version:

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

102 lines 4.36 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.WelcomeContentSection = exports.WelcomeContentButton = void 0; const AbstractElement_1 = require("../AbstractElement"); /** * A button that appears in the welcome content and can be clicked to execute a command. * * To execute the command bound to this button simply run: `await button.click();`. */ class WelcomeContentButton extends AbstractElement_1.AbstractElement { /** * @param panel The panel containing the button in the welcome section * @param welcomeSection The enclosing welcome section */ constructor(panel, welcomeSection) { super(panel, welcomeSection); } /** Return the title displayed on this button */ async getTitle() { return await this.getText(); } } exports.WelcomeContentButton = WelcomeContentButton; /** * A section in an empty custom view, see: * https://code.visualstudio.com/api/extension-guides/tree-view#welcome-content * * The welcome section contains two types of elements: text entries and buttons that can be bound to commands. * The text sections can be accessed via [[getTextSections]], the buttons on the * other hand via [[getButtons]]. * This however looses the information of the order of the buttons and lines * with respect to each other. This can be remedied by using [[getContents]], * which returns both in the order that they are found (at the expense, that you * now must use typechecks to find out what you got). */ class WelcomeContentSection extends AbstractElement_1.AbstractElement { /** * @param panel The panel containing the welcome content. * @param parent The webElement in which the welcome content is embedded. */ constructor(panel, parent) { super(panel, parent); } /** * Combination of [[getButtons]] and [[getTextSections]]: returns all entries in the welcome view in the order that they appear. */ async getContents() { const elements = await this.findElements(WelcomeContentSection.locators.WelcomeContent.buttonOrText); return Promise.all(elements.map(async (e) => { const tagName = await e.getTagName(); if (tagName === 'p') { return await e.getText(); } else { return new WelcomeContentButton(e, this); } })); } /** * Returns a specific button from the welcome view that matches the given title. * @param title The title of the button to search for. * @returns A `WelcomeContentButton` if found, otherwise `undefined`. */ async getButton(title) { const buttons = await this.getButtons(); for (const btn of buttons) { if ((await btn.getTitle()) === title) { return btn; } } return undefined; } /** Finds all buttons in the welcome content */ async getButtons() { return (await this.findElements(WelcomeContentSection.locators.WelcomeContent.button)).map((elem) => new WelcomeContentButton(elem, this)); } /** * Finds all text entries in the welcome content and returns each line as an * element in an array. */ async getTextSections() { return await Promise.all((await this.findElements(WelcomeContentSection.locators.WelcomeContent.text)).map(async (elem) => await elem.getText())); } } exports.WelcomeContentSection = WelcomeContentSection; //# sourceMappingURL=WelcomeContent.js.map