Skip to content

Commit

Permalink
feat: add QuickInputButton support (#1626)
Browse files Browse the repository at this point in the history
  • Loading branch information
pospisilf authored Nov 19, 2024
1 parent 12651c7 commit 1af67fe
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
15 changes: 15 additions & 0 deletions docs/Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```
Binary file added docs/images/quickInputAction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/locators/lib/1.37.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
51 changes: 49 additions & 2 deletions packages/page-objects/src/components/workbench/input/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<QuickInputAction[]> {
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<QuickInputAction | undefined> {
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<string> {
const value = await this.getAttribute(Input.locators.ViewSection.buttonLabel);
if (value === null) {
throw new NullAttributeError(`${this.constructor.name}.getLabel returned null`);
}
return value;
}
}
2 changes: 2 additions & 0 deletions packages/page-objects/src/locators/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ export interface Locators {
title: By;
backButton: By;
multiSelectIndex: (index: number) => By;
button: By;
buttonLabel: string;
};
InputBox: {
constructor: By;
Expand Down
17 changes: 17 additions & 0 deletions tests/test-project/src/test/workbench/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 1af67fe

Please sign in to comment.