diff --git a/docs/Input.md b/docs/Input.md index b5727542d..a386cae01 100644 --- a/docs/Input.md +++ b/docs/Input.md @@ -114,4 +114,19 @@ const text = await pick.getText(); const index = pick.getIndex(); // select (click) the item (recommend to use input.selectQuickPick() if possible) await pick.select(); +// get action button(s) +const buttons = await pick.getActions(); +const button = await pick.getAction("name"); +``` + +### QuickInputAction + +![quickInputAction](./images/quickInputAction.png) + +Page object retrieved when calling `getAction` or `getActions` representing Quick Input Actions. + +```typescript +// get label +const label = await button.getLabel(); +const label1 = await((await buttons).at(1)).getLabel(); ``` diff --git a/docs/images/quickInputAction.png b/docs/images/quickInputAction.png new file mode 100644 index 000000000..9d2a6f26c Binary files /dev/null and b/docs/images/quickInputAction.png differ diff --git a/packages/locators/lib/1.37.0.ts b/packages/locators/lib/1.37.0.ts index c95595592..63da133a7 100644 --- a/packages/locators/lib/1.37.0.ts +++ b/packages/locators/lib/1.37.0.ts @@ -505,6 +505,8 @@ const input = { title: By.className('quick-input-title'), backButton: By.className('codicon-quick-input-back'), multiSelectIndex: (index: number) => By.xpath(`.//div[@role='treeitem' and @data-index='${index}']`), + button: By.xpath(`.//a[@role='button']`), + buttonLabel: 'title', }, InputBox: { constructor: By.className('quick-input-widget'), diff --git a/packages/page-objects/src/components/workbench/input/Input.ts b/packages/page-objects/src/components/workbench/input/Input.ts index 7a9f8c313..19f07c7f7 100644 --- a/packages/page-objects/src/components/workbench/input/Input.ts +++ b/packages/page-objects/src/components/workbench/input/Input.ts @@ -16,8 +16,8 @@ */ import { AbstractElement } from '../../AbstractElement'; -import { Key } from 'selenium-webdriver'; -import { QuickOpenBox } from '../../..'; +import { Key, WebElement } from 'selenium-webdriver'; +import { NullAttributeError, QuickOpenBox } from '../../..'; /** * Abstract page object for input fields @@ -292,4 +292,51 @@ export class QuickPickItem extends AbstractElement { } return false; } + + /** + * Retrieve the actions on QuickPickItem. + * @returns Promise resolving to array of QuickInputAction objects. + */ + async getActions(): Promise { + const actions: QuickInputAction[] = []; + const elements = await this.findElements(Input.locators.Input.button); + for (const element of elements) { + actions.push(await new QuickInputAction(element, this).wait()); + } + return actions; + } + + /** + * Retrieve the specific action on QuickPickItem. + * @param label Name of QuickPickItem. + * @returns Promise resolving QuickInputAction if item exists or undefined. + */ + async getAction(label: string): Promise { + const actions = await this.getActions(); + for (const action of actions) { + if ((await action.getLabel()) === label) { + return action; + } + } + } +} + +/** + * Action bound to a QuickPickItem. + */ +export class QuickInputAction extends AbstractElement { + constructor(element: WebElement, viewPart: QuickPickItem) { + super(element, viewPart); + } + + /** + * Get label of the action button. + */ + async getLabel(): Promise { + const value = await this.getAttribute(Input.locators.ViewSection.buttonLabel); + if (value === null) { + throw new NullAttributeError(`${this.constructor.name}.getLabel returned null`); + } + return value; + } } diff --git a/packages/page-objects/src/locators/locators.ts b/packages/page-objects/src/locators/locators.ts index 2dc672ac6..ebf7c4f24 100644 --- a/packages/page-objects/src/locators/locators.ts +++ b/packages/page-objects/src/locators/locators.ts @@ -504,6 +504,8 @@ export interface Locators { title: By; backButton: By; multiSelectIndex: (index: number) => By; + button: By; + buttonLabel: string; }; InputBox: { constructor: By; diff --git a/tests/test-project/src/test/workbench/input.test.ts b/tests/test-project/src/test/workbench/input.test.ts index 9048b3d16..775778aa5 100644 --- a/tests/test-project/src/test/workbench/input.test.ts +++ b/tests/test-project/src/test/workbench/input.test.ts @@ -122,6 +122,23 @@ describe('QuickPickItem', () => { const desc = await pick.getDescription(); expect(desc).has.string('Test Description'); }); + + it('getActions works', async function () { + const prompt = await new Workbench().openCommandPrompt(); + await prompt.setText(`>Extension Test Command`); + item = (await prompt.getQuickPicks())[0]; + expect((await item.getActions()).length).equals(1); + }); + + it('getLabel of Action Button works', async function () { + const button = await (await item.getActions()).at(0); + expect(await button?.getLabel()).to.contain('Configure Keybinding'); + }); + + it('getAction works', async function () { + const button = await item.getAction('Configure Keybinding'); + expect(button).not.undefined; + }); }); describe('InputBox', () => {