Skip to content

Commit

Permalink
fix: Throw the error when broken methods are used for testing of VS C…
Browse files Browse the repository at this point in the history
…ode 1.87+

Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek committed Mar 20, 2024
1 parent c7a5454 commit 80f3d1b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 46 deletions.
3 changes: 2 additions & 1 deletion locators/lib/1.37.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const bottomBar = {
},
OutputView: {
constructor: By.id('workbench.panel.output'),
actionsLabel: 'Output actions'
actionsLabel: 'Output actions',
optionByName: (name: string) => By.xpath(`.//option[@value='${name}']`)
},
WebviewView: {
iframe: By.xpath(`//div[not(@class)]/iframe[@class='webview ready' and not(@data-parent-flow-to-element-id)]`)
Expand Down
43 changes: 6 additions & 37 deletions page-objects/src/components/bottomBar/AbstractViews.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Key, WebElement } from 'selenium-webdriver';
import { Key } from 'selenium-webdriver';
import { ElementWithContexMenu } from "../ElementWithContextMenu";

/**
Expand Down Expand Up @@ -31,6 +31,9 @@ export abstract class ChannelView extends ElementWithContexMenu {
* @returns Promise resolving to the current channel name
*/
async getCurrentChannel(): Promise<string> {
if(ChannelView.versionInfo.version >= '1.87.0' && process.platform !== 'darwin') {
throw Error(`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');
}
Expand All @@ -40,43 +43,9 @@ export abstract class ChannelView extends ElementWithContexMenu {
* @param name name of the channel to open
*/
async selectChannel(name: string): Promise<void> {
const rows = await this.getOptions();
for (let i = 0; i < rows.length; i++) {
if ((await rows[i].getAttribute('class')).indexOf('disabled') < 0) {
const text = await (await rows[i].findElement(ChannelView.locators.BottomBarViews.channelText)).getText();
if (name === text) {
await rows[i].click();
await new Promise(res => setTimeout(res, 500));
return;
}
}
}
throw new Error(`Channel ${name} not found`);
}

private async getOptions(): Promise<WebElement[]> {
const combo = await this.enclosingItem.findElement(ChannelView.locators.BottomBarViews.channelCombo);
const workbench = await this.getDriver().findElement(ChannelView.locators.Workbench.constructor);
const menus = await workbench.findElements(ChannelView.locators.ContextMenu.contextView);
let menu!: WebElement;

if (menus.length < 1) {
await combo.click();
await this.getDriver().sleep(500);
menu = await workbench.findElement(ChannelView.locators.ContextMenu.contextView);
return await menu.findElements(ChannelView.locators.BottomBarViews.channelRow);
} else if (await menus[0].isDisplayed()) {
await combo.click();
await this.getDriver().sleep(500);
}
await combo.click();
await this.getDriver().sleep(500);
menu = await workbench.findElement(ChannelView.locators.ContextMenu.contextView);
if (!await menu.isDisplayed()) {
await combo.click();
await this.getDriver().sleep(500);
}
return await menu.findElements(ChannelView.locators.BottomBarViews.channelRow);
const option = await combo.findElement(ChannelView.locators.OutputView.optionByName(name));
await option.click();
}
}

Expand Down
10 changes: 2 additions & 8 deletions page-objects/src/components/bottomBar/Views.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Key, until } from "selenium-webdriver";
import { BottomBarPanel, ContentAssist, InputBox, Workbench } from "../..";
import { BottomBarPanel, ContentAssist, Workbench } from "../..";
import { TextView, ChannelView } from "./AbstractViews";
import { ElementWithContexMenu } from "../ElementWithContextMenu";

Expand All @@ -17,13 +17,7 @@ export class OutputView extends TextView {
* @param name name of the channel to open
*/
async selectChannel(name: string): Promise<void> {
if (process.platform === 'darwin') {
await new Workbench().executeCommand('Output: Show Output Channels...');
const input = await InputBox.create();
await input.selectQuickPick(name);
} else {
await super.selectChannel(name);
}
await super.selectChannel(name);
}
}

Expand Down
3 changes: 3 additions & 0 deletions page-objects/src/components/sidebar/debug/DebugView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export class DebugView extends SideBarView {
* @returns Promise resolving to the title
*/
async getLaunchConfiguration(): Promise<string> {
if(DebugView.versionInfo.version >= '1.87.0' && process.platform !== 'darwin') {
throw Error(`The 'DebugView.getLaunchConfiguration' 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 action = await this.getTitlePart().findElement(DebugView.locators.DebugView.launchCombo);
const combo = await action.findElement(DebugView.locators.DebugView.launchSelect);
return await combo.getAttribute('title');
Expand Down
1 change: 1 addition & 0 deletions page-objects/src/locators/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface Locators {
OutputView: {
constructor: By
actionsLabel: string
optionByName: (name: string) => By
}
WebviewView: {
iframe: By
Expand Down
6 changes: 6 additions & 0 deletions test/test-project/src/test/bottomBar/views-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ describe('Output View/Text Views', function () {
});

it('getCurrentChannel returns the selected channel name', async function () {
if(process.platform !== 'darwin' && VSBrowser.instance.version >= '1.87.0') {
this.skip();
}
const channel = await view.getCurrentChannel();
expect(channel).not.empty;
});

it('selectChannel works', async function () {
this.timeout(10000);
if(process.platform !== 'darwin' && VSBrowser.instance.version >= '1.87.0') {
this.skip();
}
await view.selectChannel('Tasks');
const final = await view.getCurrentChannel();
expect('Tasks').equals(final);
Expand Down
6 changes: 6 additions & 0 deletions test/test-project/src/test/debug/debug-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe('Debugging', function () {

describe('Debug View', () => {
it('getLaunchConfiguration works', async function () {
if(process.platform !== 'darwin' && VSBrowser.instance.version >= '1.87.0') {
this.skip();
}
const config = await view.getLaunchConfiguration();
expect(config).equals('Test Launch');
});
Expand All @@ -45,6 +48,9 @@ describe('Debugging', function () {
});

it('selectLaunchConfiguration works', async function () {
if(process.platform !== 'darwin' && VSBrowser.instance.version >= '1.87.0') {
this.skip();
}
await view.selectLaunchConfiguration('Test Launch2');
const config = await view.getLaunchConfiguration();
expect(config).equals('Test Launch2');
Expand Down

0 comments on commit 80f3d1b

Please sign in to comment.