UNPKG

@redhat-developer/page-objects

Version:

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

152 lines 5.75 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.Workbench = void 0; const AbstractElement_1 = require("../AbstractElement"); const selenium_webdriver_1 = require("selenium-webdriver"); const TitleBar_1 = require("../menu/TitleBar"); const SideBarView_1 = require("../sidebar/SideBarView"); const ActivityBar_1 = require("../activityBar/ActivityBar"); const StatusBar_1 = require("../statusBar/StatusBar"); const EditorView_1 = require("../editor/EditorView"); const BottomBarPanel_1 = require("../bottomBar/BottomBarPanel"); const Notification_1 = require("./Notification"); const QuickOpenBox_1 = require("./input/QuickOpenBox"); const SettingsEditor_1 = require("../editor/SettingsEditor"); const InputBox_1 = require("./input/InputBox"); const compare_versions_1 = require("compare-versions"); /** * Handler for general workbench related actions */ class Workbench extends AbstractElement_1.AbstractElement { constructor() { super(Workbench.locators.Workbench.constructor); } /** * Get a title bar handle */ getTitleBar() { return new TitleBar_1.TitleBar(); } /** * Get a side bar handle */ getSideBar() { return new SideBarView_1.SideBarView(); } /** * Get an activity bar handle */ getActivityBar() { return new ActivityBar_1.ActivityBar(); } /** * Get a status bar handle */ getStatusBar() { return new StatusBar_1.StatusBar(); } /** * Get a bottom bar handle */ getBottomBar() { return new BottomBarPanel_1.BottomBarPanel(); } /** * Get a handle for the editor view */ getEditorView() { return new EditorView_1.EditorView(); } /** * Get all standalone notifications (notifications outside the notifications center) * @returns Promise resolving to array of Notification objects */ async getNotifications() { const notifications = []; let container; try { container = await this.findElement(Workbench.locators.Workbench.notificationContainer); } catch (err) { return []; } const elements = await container.findElements(Workbench.locators.Workbench.notificationItem); for (const element of elements) { notifications.push(await new Notification_1.StandaloneNotification(element).wait()); } return notifications; } /** * Opens the notifications center * @returns Promise resolving to NotificationsCenter object */ async openNotificationsCenter() { return await new StatusBar_1.StatusBar().openNotificationsCenter(); } /** * Opens the settings editor * * @returns promise that resolves to a SettingsEditor instance */ async openSettings() { await this.executeCommand('open user settings'); await new EditorView_1.EditorView().openEditor('Settings'); await Workbench.driver.wait(selenium_webdriver_1.until.elementLocated(Workbench.locators.Editor.constructor)); await new Promise((res) => setTimeout(res, 500)); return new SettingsEditor_1.SettingsEditor(); } /** * Open the VS Code command line prompt * @returns Promise resolving to InputBox (vscode 1.44+) or QuickOpenBox (vscode up to 1.43) object */ async openCommandPrompt() { const webview = await new EditorView_1.EditorView().findElements(EditorView_1.EditorView.locators.EditorView.webView); if (webview.length > 0) { const tab = await new EditorView_1.EditorView().getActiveTab(); if (tab) { await tab.sendKeys(selenium_webdriver_1.Key.F1); return await InputBox_1.InputBox.create(); } } const driver = this.getDriver(); await driver.actions().keyDown(Workbench.ctlKey).keyDown(selenium_webdriver_1.Key.SHIFT).sendKeys('p').perform(); if ((0, compare_versions_1.satisfies)(Workbench.versionInfo.version, '>=1.44.0')) { return await InputBox_1.InputBox.create(); } return await QuickOpenBox_1.QuickOpenBox.create(); } /** * Open the command prompt, type in a command and execute * @param command text of the command to be executed * @returns Promise resolving when the command prompt is confirmed */ async executeCommand(command) { const prompt = await this.openCommandPrompt(); await prompt.setText(`>${command}`); const quickPicks = await Promise.all((await prompt.getQuickPicks()).map((item) => item.getLabel())); if (quickPicks.includes(command)) { await prompt.selectQuickPick(command); } else { await prompt.confirm(); } } } exports.Workbench = Workbench; //# sourceMappingURL=Workbench.js.map