Skip to content

Commit 1af67fe

Browse files
authored
feat: add QuickInputButton support (#1626)
1 parent 12651c7 commit 1af67fe

File tree

6 files changed

+85
-2
lines changed

6 files changed

+85
-2
lines changed

docs/Input.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,19 @@ const text = await pick.getText();
114114
const index = pick.getIndex();
115115
// select (click) the item (recommend to use input.selectQuickPick() if possible)
116116
await pick.select();
117+
// get action button(s)
118+
const buttons = await pick.getActions();
119+
const button = await pick.getAction("name");
120+
```
121+
122+
### QuickInputAction
123+
124+
![quickInputAction](./images/quickInputAction.png)
125+
126+
Page object retrieved when calling `getAction` or `getActions` representing Quick Input Actions.
127+
128+
```typescript
129+
// get label
130+
const label = await button.getLabel();
131+
const label1 = await((await buttons).at(1)).getLabel();
117132
```

docs/images/quickInputAction.png

10.7 KB
Loading

packages/locators/lib/1.37.0.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ const input = {
505505
title: By.className('quick-input-title'),
506506
backButton: By.className('codicon-quick-input-back'),
507507
multiSelectIndex: (index: number) => By.xpath(`.//div[@role='treeitem' and @data-index='${index}']`),
508+
button: By.xpath(`.//a[@role='button']`),
509+
buttonLabel: 'title',
508510
},
509511
InputBox: {
510512
constructor: By.className('quick-input-widget'),

packages/page-objects/src/components/workbench/input/Input.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717

1818
import { AbstractElement } from '../../AbstractElement';
19-
import { Key } from 'selenium-webdriver';
20-
import { QuickOpenBox } from '../../..';
19+
import { Key, WebElement } from 'selenium-webdriver';
20+
import { NullAttributeError, QuickOpenBox } from '../../..';
2121

2222
/**
2323
* Abstract page object for input fields
@@ -292,4 +292,51 @@ export class QuickPickItem extends AbstractElement {
292292
}
293293
return false;
294294
}
295+
296+
/**
297+
* Retrieve the actions on QuickPickItem.
298+
* @returns Promise resolving to array of QuickInputAction objects.
299+
*/
300+
async getActions(): Promise<QuickInputAction[]> {
301+
const actions: QuickInputAction[] = [];
302+
const elements = await this.findElements(Input.locators.Input.button);
303+
for (const element of elements) {
304+
actions.push(await new QuickInputAction(element, this).wait());
305+
}
306+
return actions;
307+
}
308+
309+
/**
310+
* Retrieve the specific action on QuickPickItem.
311+
* @param label Name of QuickPickItem.
312+
* @returns Promise resolving QuickInputAction if item exists or undefined.
313+
*/
314+
async getAction(label: string): Promise<QuickInputAction | undefined> {
315+
const actions = await this.getActions();
316+
for (const action of actions) {
317+
if ((await action.getLabel()) === label) {
318+
return action;
319+
}
320+
}
321+
}
322+
}
323+
324+
/**
325+
* Action bound to a QuickPickItem.
326+
*/
327+
export class QuickInputAction extends AbstractElement {
328+
constructor(element: WebElement, viewPart: QuickPickItem) {
329+
super(element, viewPart);
330+
}
331+
332+
/**
333+
* Get label of the action button.
334+
*/
335+
async getLabel(): Promise<string> {
336+
const value = await this.getAttribute(Input.locators.ViewSection.buttonLabel);
337+
if (value === null) {
338+
throw new NullAttributeError(`${this.constructor.name}.getLabel returned null`);
339+
}
340+
return value;
341+
}
295342
}

packages/page-objects/src/locators/locators.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ export interface Locators {
504504
title: By;
505505
backButton: By;
506506
multiSelectIndex: (index: number) => By;
507+
button: By;
508+
buttonLabel: string;
507509
};
508510
InputBox: {
509511
constructor: By;

tests/test-project/src/test/workbench/input.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ describe('QuickPickItem', () => {
122122
const desc = await pick.getDescription();
123123
expect(desc).has.string('Test Description');
124124
});
125+
126+
it('getActions works', async function () {
127+
const prompt = await new Workbench().openCommandPrompt();
128+
await prompt.setText(`>Extension Test Command`);
129+
item = (await prompt.getQuickPicks())[0];
130+
expect((await item.getActions()).length).equals(1);
131+
});
132+
133+
it('getLabel of Action Button works', async function () {
134+
const button = await (await item.getActions()).at(0);
135+
expect(await button?.getLabel()).to.contain('Configure Keybinding');
136+
});
137+
138+
it('getAction works', async function () {
139+
const button = await item.getAction('Configure Keybinding');
140+
expect(button).not.undefined;
141+
});
125142
});
126143

127144
describe('InputBox', () => {

0 commit comments

Comments
 (0)