Skip to content

Commit

Permalink
feat: Support for editor action buttons with dropdown
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>

test

Signed-off-by: Dominik Jelinek <[email protected]>

test 2

Signed-off-by: Dominik Jelinek <[email protected]>

test

Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek committed Jul 17, 2024
1 parent 3b452e7 commit 9bffd73
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/locators/lib/1.37.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const editor = {
actionContainer: By.className('editor-actions'),
actionItem: By.className('action-label'),
attribute: 'title',
dropdown: 'aria-haspopup',
},
Editor: {
constructor: By.className('editor-instance'),
Expand Down
40 changes: 37 additions & 3 deletions packages/page-objects/src/components/editor/EditorAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/

import { EditorGroup } from './EditorView';
import { AbstractElement } from '../AbstractElement';
import { WebElement } from '../..';
import { By, ContextMenu, Key, WebElement } from '../..';
import { ElementWithContexMenu } from '../ElementWithContextMenu';
import { ChromiumWebDriver } from 'selenium-webdriver/chromium';

export class EditorAction extends ElementWithContexMenu {

export class EditorAction extends AbstractElement {
constructor(element: WebElement, parent: EditorGroup) {
super(element, parent);
}
Expand All @@ -31,3 +33,35 @@ export class EditorAction extends AbstractElement {
return await this.getAttribute(EditorAction.locators.EditorView.attribute);
}
}

export class EditorActionDropdown extends EditorAction {
async open(): Promise<ContextMenu> {
await this.click();
const shadowRootHost = await this.enclosingItem.findElements(By.className('shadow-root-host'));
const actions = this.getDriver().actions();
await actions.clear();
await actions.sendKeys(Key.ESCAPE).perform();
const webdriverCapabilities = await (this.getDriver() as ChromiumWebDriver).getCapabilities();
const chromiumVersion = webdriverCapabilities.getBrowserVersion();
if (shadowRootHost.length > 0) {
if ((await this.getAttribute('aria-expanded')) !== 'true') {
await this.click();
}
let shadowRoot;
const webdriverCapabilities = await (this.getDriver() as ChromiumWebDriver).getCapabilities();
const chromiumVersion = webdriverCapabilities.getBrowserVersion();
if (chromiumVersion && parseInt(chromiumVersion.split('.')[0]) >= 96) {
shadowRoot = await shadowRootHost[0].getShadowRoot();
return new ContextMenu(await shadowRoot.findElement(By.className('monaco-menu-container'))).wait();
} else {
shadowRoot = (await this.getDriver().executeScript('return arguments[0].shadowRoot', shadowRootHost[0])) as WebElement;
return new ContextMenu(shadowRoot).wait();
}
} else if (chromiumVersion && parseInt(chromiumVersion.split('.')[0]) >= 100) {
await this.click();
const workbench = await this.getDriver().findElement(ElementWithContexMenu.locators.Workbench.constructor);
return new ContextMenu(workbench).wait();
}
return await super.openContextMenu();
}
}
13 changes: 11 additions & 2 deletions packages/page-objects/src/components/editor/EditorView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { AbstractElement } from '../AbstractElement';
import { ElementWithContexMenu } from '../ElementWithContextMenu';
import { DiffEditor } from './DiffEditor';
import { Editor } from './Editor';
import { EditorAction } from './EditorAction';
import { EditorAction, EditorActionDropdown } from './EditorAction';
import { SettingsEditor } from './SettingsEditor';
import { WebView } from './WebView';

Expand Down Expand Up @@ -339,7 +339,16 @@ export class EditorGroup extends AbstractElement {
*/
async getActions(): Promise<EditorAction[]> {
const actions = await this.findElement(EditorGroup.locators.EditorView.actionContainer).findElements(EditorGroup.locators.EditorView.actionItem);
return actions.map((action) => new EditorAction(action, this));
return Promise.all(
actions.map(async (action) => {
const dropdown = await action.getAttribute(EditorGroup.locators.EditorView.dropdown);
if (dropdown) {
return new EditorActionDropdown(action, this);
} else {
return new EditorAction(action, this);
}
}),
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/page-objects/src/locators/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export interface Locators {
actionContainer: By;
actionItem: By;
attribute: string;
dropdown: string;
};
Editor: {
constructor: By;
Expand Down
9 changes: 7 additions & 2 deletions tests/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,15 @@
}
},
"menus": {
"editor/title": [
"editor/title/run": [
{
"command": "extension.helloWorld",
"group": "navigation",
"group": "1_run@1",
"when": "resourceFilename =~ /Untitled.*$/"
},
{
"command": "extension.helloWorld2",
"group": "1_run@2",
"when": "resourceFilename =~ /Untitled.*$/"
}
],
Expand Down
23 changes: 23 additions & 0 deletions tests/test-project/src/test/editor/editorView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
DiffEditor,
InputBox,
VSBrowser,
EditorActionDropdown,
NotificationType,
} from 'vscode-extension-tester';

describe('EditorView', function () {
Expand Down Expand Up @@ -134,6 +136,27 @@ describe('EditorView', function () {
expect(editorAction).not.undefined;
});

(process.platform === 'darwin' ? it.skip : it)('Editor getAction dropdown', async function () {
this.timeout(15_000);
await new EditorView().openEditor('Untitled-2');
const editorAction = (await view.getAction('Run or Debug...')) as EditorActionDropdown;

if (editorAction) {
const menu = await editorAction.open();
await menu.select('Hello a World');

const center = await new Workbench().openNotificationsCenter();
const notifications = await center.getNotifications(NotificationType.Any);

expect(await notifications.at(0)?.getText()).is.equal('Hello World, Test Project!');

await center.clearAllNotifications();
await center.close();
} else {
expect.fail('Cannot find any dropdown editor action!');
}
});

describe('Editor Tab', function () {
let tab2: EditorTab;
let tab3: EditorTab;
Expand Down

0 comments on commit 9bffd73

Please sign in to comment.