@redhat-developer/page-objects
Version:
Page Object API implementation for a VS Code editor used by ExTester framework.
107 lines • 4.77 kB
JavaScript
;
/**
* 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.TextView = exports.ChannelView = void 0;
const selenium_webdriver_1 = require("selenium-webdriver");
const ElementWithContextMenu_1 = require("../ElementWithContextMenu");
const compare_versions_1 = require("compare-versions");
/**
* View with channel selector
*/
class ChannelView extends ElementWithContextMenu_1.ElementWithContextMenu {
actionsLabel;
/**
* Get names of all selectable channels
* @returns Promise resolving to array of strings - channel names
*/
async getChannelNames() {
const names = [];
const elements = await (await this.enclosingItem.findElement(ChannelView.locators.BottomBarViews.actionsContainer(this.actionsLabel))).findElements(ChannelView.locators.BottomBarViews.channelOption);
await Promise.all(elements.map(async (element) => {
const disabled = await element.getAttribute('disabled');
if (!disabled) {
names.push(await element.getAttribute('value'));
}
}));
return names;
}
/**
* Get name of the current channel
* @returns Promise resolving to the current channel name
* @deprecated For VS Code 1.88+ this method won't be working any more
*/
async getCurrentChannel() {
if ((0, compare_versions_1.compareVersions)(ChannelView.versionInfo.version, '1.87.0') >= 0 && process.platform !== 'darwin') {
throw Error(`DEPRECATED METHOD! The 'ChannelView.getCurrentChannel' method is broken! Read more information in 'Known Issues > Limitations in testing with VS Code 1.87+' - https://github.com/microsoft/vscode/issues/206897.`);
}
const combo = await this.enclosingItem.findElement(ChannelView.locators.BottomBarViews.channelCombo);
return await combo.getAttribute('title');
}
/**
* Select a channel using the selector combo
* @param name name of the channel to open
*/
async selectChannel(name) {
const combo = await this.enclosingItem.findElement(ChannelView.locators.BottomBarViews.channelCombo);
const option = await combo.findElement(ChannelView.locators.OutputView.optionByName(name));
await option.click();
}
}
exports.ChannelView = ChannelView;
/**
* View with channel selection and text area
*/
class TextView extends ChannelView {
/**
* Get all text from the currently open channel
* @returns Promise resolving to the view's text
*/
async getText() {
const clipboard = (await import('clipboardy')).default;
let originalClipboard = '';
try {
originalClipboard = clipboard.readSync();
}
catch (error) {
// workaround issue https://github.com/redhat-developer/vscode-extension-tester/issues/835
// do not fail if clipboard is empty
}
const textarea = await this.findElement(ChannelView.locators.BottomBarViews.textArea);
await textarea.sendKeys(selenium_webdriver_1.Key.chord(TextView.ctlKey, 'a'));
await textarea.sendKeys(selenium_webdriver_1.Key.chord(TextView.ctlKey, 'c'));
const text = clipboard.readSync();
// workaround as we are getting "element click intercepted" during the send keys actions.
// await textarea.click();
if (originalClipboard.length > 0) {
clipboard.writeSync(originalClipboard);
}
return text;
}
/**
* Clear the text in the current channel
* @returns Promise resolving when the clear text button is pressed
*/
async clearText() {
await this.enclosingItem
.findElement(ChannelView.locators.BottomBarViews.actionsContainer(this.actionsLabel))
.findElement(ChannelView.locators.BottomBarViews.clearText)
.click();
}
}
exports.TextView = TextView;
//# sourceMappingURL=AbstractViews.js.map