@redhat-developer/page-objects
Version:
Page Object API implementation for a VS Code editor used by ExTester framework.
192 lines • 8.85 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.MultiScmProvider = exports.SingleScmProvider = exports.NewScmView = void 0;
const ScmView_1 = require("./ScmView");
const selenium_webdriver_1 = require("selenium-webdriver");
const ElementWithContextMenu_1 = require("../../ElementWithContextMenu");
const ViewTitlePart_1 = require("../ViewTitlePart");
const compare_versions_1 = require("compare-versions");
/**
* New SCM view for code 1.47 onwards
*/
class NewScmView extends ScmView_1.ScmView {
async getProviders() {
const inputs = await this.findElements(NewScmView.locators.ScmView.inputField);
if (inputs.length < 1) {
return [];
}
const providers = await this.findElements(NewScmView.locators.ScmView.multiScmProvider);
if (inputs.length === 1 && providers.length < 1) {
const element = await this.findElement(NewScmView.locators.ScmView.singleScmProvider);
return [await new SingleScmProvider(element, this).wait()];
}
const elements = await this.findElements(NewScmView.locators.ScmView.multiProviderItem);
return await Promise.all(elements.map(async (element) => new MultiScmProvider(element, this).wait()));
}
}
exports.NewScmView = NewScmView;
/**
* Implementation for a single SCM provider
*/
class SingleScmProvider extends ScmView_1.ScmProvider {
/**
* There is no title available for a single provider
*/
async getTitle() {
return '';
}
/**
* No title available for single provider
*/
async getType() {
return '';
}
async takeAction(title) {
const view = this.enclosingItem;
let actions = [];
let names = [];
const buttons = [];
if ((0, compare_versions_1.satisfies)(ScmView_1.ScmProvider.versionInfo.version, '>=1.93.0')) {
actions = await this.getProviderHeaderActions(view);
names = await Promise.all(actions.map(async (action) => await action.getAttribute(ScmView_1.ScmProvider.locators.ScmView.actionLabel)));
}
else {
const titlePart = view.getTitlePart();
const elements = await titlePart.findElements(ScmView_1.ScmView.locators.ScmView.action);
for (const element of elements) {
const title = await element.getAttribute(ScmView_1.ScmView.locators.ScmView.actionLabel);
buttons.push(await new ViewTitlePart_1.TitleActionButton(ScmView_1.ScmView.locators.ScmView.actionConstructor(title), titlePart).wait());
}
names = await Promise.all(buttons.map(async (button) => button.getTitle()));
}
const index = names.findIndex((item) => item === title);
if (index > -1) {
if ((0, compare_versions_1.satisfies)(ScmView_1.ScmProvider.versionInfo.version, '>=1.93.0')) {
actions = await this.getProviderHeaderActions(view);
await actions[index].click();
}
else {
await buttons[index].click();
}
return true;
}
return false;
}
async getProviderHeaderActions(view) {
const header = await view.findElement(ScmView_1.ScmView.locators.ScmView.sourceControlSection);
await this.getDriver().actions().move({ origin: header }).perform();
await this.getDriver().sleep(1_000);
return await header.findElements(ScmView_1.ScmProvider.locators.ScmView.action);
}
async openMoreActions() {
const view = this.enclosingItem;
return await new ScmView_1.MoreAction(view).openContextMenu();
}
async getChanges(staged = false) {
const count = await this.getChangeCount(staged);
const elements = [];
if (count > 0) {
const locator = staged ? ScmView_1.ScmProvider.locators.ScmView.stagedChanges : ScmView_1.ScmProvider.locators.ScmView.changes;
const header = await this.findElement(locator);
const startIndex = +(await header.getAttribute('data-index'));
const depth = +(await header.getAttribute('aria-level')) + 1;
const items = await this.findElements(NewScmView.locators.ScmView.itemLevel(depth));
for (const item of items) {
const index = +(await item.getAttribute('data-index'));
if (index > startIndex && index <= startIndex + count) {
elements.push(item);
}
}
}
return Promise.all(elements.map(async (element) => new ScmView_1.ScmChange(element, this).wait()));
}
}
exports.SingleScmProvider = SingleScmProvider;
/**
* Implementation of an SCM provider when multiple providers are available
*/
class MultiScmProvider extends ScmView_1.ScmProvider {
async takeAction(title) {
const actions = await this.findElements(ScmView_1.ScmProvider.locators.ScmView.action);
const names = await Promise.all(actions.map(async (action) => await action.getAttribute('title')));
const index = names.findIndex((item) => item === title);
if (index > -1) {
await actions[index].click();
return true;
}
return false;
}
async openMoreActions() {
return await new MultiMoreAction(this).openContextMenu();
}
async commitChanges(message) {
const index = +(await this.getAttribute('data-index')) + 1;
const input = await this.enclosingItem.findElement(NewScmView.locators.ScmView.itemIndex(index));
await input.clear();
await input.sendKeys(message);
await input.sendKeys(selenium_webdriver_1.Key.chord(ScmView_1.ScmProvider.ctlKey, selenium_webdriver_1.Key.ENTER));
}
async getChanges(staged = false) {
const count = await this.getChangeCount(staged);
const elements = [];
if (count > 0) {
const index = +(await this.getAttribute('data-index'));
const locator = staged ? ScmView_1.ScmProvider.locators.ScmView.stagedChanges : ScmView_1.ScmProvider.locators.ScmView.changes;
const headers = await this.enclosingItem.findElements(locator);
let header;
for (const item of headers) {
if (+(await item.getAttribute('data-index')) > index) {
header = item;
}
}
if (!header) {
return [];
}
const startIndex = +(await header.getAttribute('data-index'));
const depth = +(await header.getAttribute('aria-level')) + 1;
const items = await this.enclosingItem.findElements(NewScmView.locators.ScmView.itemLevel(depth));
for (const item of items) {
const index = +(await item.getAttribute('data-index'));
if (index > startIndex && index <= startIndex + count) {
elements.push(item);
}
}
}
return await Promise.all(elements.map(async (element) => new ScmView_1.ScmChange(element, this).wait()));
}
async getChangeCount(staged = false) {
const locator = staged ? ScmView_1.ScmProvider.locators.ScmView.stagedChanges : ScmView_1.ScmProvider.locators.ScmView.changes;
const rows = await this.enclosingItem.findElements(locator);
const index = +(await this.getAttribute('data-index'));
for (const row of rows) {
if (+(await row.getAttribute('data-index')) > index) {
const count = await rows[0].findElement(ScmView_1.ScmChange.locators.ScmView.changeCount);
return +(await count.getText());
}
}
return 0;
}
}
exports.MultiScmProvider = MultiScmProvider;
class MultiMoreAction extends ElementWithContextMenu_1.ElementWithContextMenu {
constructor(scm) {
super(ScmView_1.MoreAction.locators.ScmView.multiMore, scm);
}
}
//# sourceMappingURL=NewScmView.js.map