Skip to content

Commit

Permalink
Support retrieving quickpick items when using a multi-select quickpick
Browse files Browse the repository at this point in the history
Closes #690
  • Loading branch information
ewanharris authored and djelinek committed Oct 4, 2023
1 parent 9954b70 commit 22f5f8d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 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 @@ -422,7 +422,8 @@ const input = {
quickPickSelectAll: By.className('quick-input-check-all'),
titleBar: By.className('quick-input-titlebar'),
title: By.className('quick-input-title'),
backButton: By.className('codicon-quick-input-back')
backButton: By.className('codicon-quick-input-back'),
multiSelectIndex: (index: number) => By.xpath(`.//div[@role='treeitem' and @data-index='${index}']`)
},
InputBox: {
constructor: By.className('quick-input-widget'),
Expand Down
4 changes: 3 additions & 1 deletion locators/lib/1.43.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { By } from "selenium-webdriver";
export const diff: LocatorDiff = {
locators: {
Input: {
quickPickIndex: (index: number) => By.xpath(`.//div[@role='listitem' and @data-index='${index}']`)
quickPickIndex: (index: number) => By.xpath(`.//div[@role='listitem' and @data-index='${index}']`),
multiSelectIndex: (index: number) => By.xpath(`.//div[@role='listitem' and @data-index='${index}']`)

},
NotificationsCenter: {
close: By.className('codicon-chevron-down')
Expand Down
3 changes: 2 additions & 1 deletion locators/lib/1.44.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { By } from "selenium-webdriver";
export const diff: LocatorDiff = {
locators: {
Input: {
quickPickIndex: (index: number) => By.xpath(`.//div[@role='option' and @data-index='${index}']`)
quickPickIndex: (index: number) => By.xpath(`.//div[@role='option' and @data-index='${index}']`),
multiSelectIndex: (index: number) => By.xpath(`.//div[@role='option' and @data-index='${index}']`)
}
}
}
5 changes: 5 additions & 0 deletions locators/lib/1.76.0.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { LocatorDiff } from "monaco-page-objects";
import { By } from "selenium-webdriver";

export const diff: LocatorDiff = {
locators: {
EditorView: {
attribute: 'aria-label'
},
TreeItem: {
actionTitle: 'aria-label'
},
Input: {
multiSelectIndex: (index: number) => By.xpath(`.//div[@role='checkbox' and @data-index='${index}']`)
}
}
}
7 changes: 6 additions & 1 deletion page-objects/src/components/workbench/input/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,16 @@ export abstract class Input extends AbstractElement {
export class QuickPickItem extends AbstractElement {
private index: number;

constructor(index: number, input: Input) {
constructor(index: number, input: Input, isMultiSelect = false) {
let locator = Input.locators.Input.quickPickIndex(index);
if (input instanceof QuickOpenBox) {
locator = Input.locators.Input.quickPickPosition(index);
}

if (isMultiSelect) {
locator = Input.locators.Input.multiSelectIndex(index);
}

super(locator, input);
this.index = index;
}
Expand Down
15 changes: 15 additions & 0 deletions page-objects/src/components/workbench/input/InputBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ export class InputBox extends Input {
return picks;
}

async getCheckboxes(): Promise<QuickPickItem[]> {
const picks: QuickPickItem[] = [];
const elements = await this.findElement(InputBox.locators.InputBox.quickList)
.findElement(InputBox.locators.InputBox.rows)
.findElements(InputBox.locators.InputBox.row);

for (const element of elements) {
if (await element.isDisplayed()) {
picks.push(await new QuickPickItem(+await element.getAttribute('data-index'), this, true).wait());
}
}

return picks;
}

/**
* Find whether the input is showing an error
* @returns Promise resolving to notification message
Expand Down
3 changes: 2 additions & 1 deletion page-objects/src/locators/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ export interface Locators {
quickPickSelectAll: By,
titleBar: By,
title: By,
backButton: By
backButton: By,
multiSelectIndex: (index: number) => By
}
InputBox: {
constructor: By
Expand Down
10 changes: 9 additions & 1 deletion test/test-project/src/test/workbench/input-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('QuickPickItem', () => {
});
});

describe('InputBox', () => {
describe.only('InputBox', () => {
let input: InputBox;

before(async function () {
Expand Down Expand Up @@ -186,4 +186,12 @@ describe('Multiple selection input', () => {
const checkbox = await input.findElement(By.css('input'));
expect(await checkbox.isSelected()).is.false;
});

it('allows retrieving quickpicks', async () => {
const [first] = await input.getCheckboxes();
expect(await first.getText()).equals('test1');
await first.select();
const checkbox = await first.findElement(By.css('input'));
expect(await checkbox.isSelected()).is.true;
});
});

0 comments on commit 22f5f8d

Please sign in to comment.