Skip to content

Commit 4f8ed3c

Browse files
committed
feat(e2e): add choose from dropdown function to basepage
1 parent 506a349 commit 4f8ed3c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

pages/BasePage.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,22 @@ export class BasePage {
124124
const submitButton = this.page.getByRole('button', { name: buttonName, exact: true });
125125
await this.clickElement(submitButton);
126126
}
127+
128+
public async clickAndChooseFromDropdownByText(
129+
dropdownLocator: (string | Locator),
130+
dropdownList: Locator,
131+
dropdownItemText: string,
132+
) {
133+
await this.clickElement(dropdownLocator);
134+
await this.page.waitForTimeout(2000);
135+
const dropDownList = await dropdownList.all();
136+
for (let item of dropDownList) {
137+
const itemText = await this.getInnerText(item);
138+
if (itemText === dropdownItemText) {
139+
await item.click();
140+
return;
141+
}
142+
}
143+
throw new Error(`the item ${dropdownItemText} does not exist in dropdown!`);
144+
}
127145
}

0 commit comments

Comments
 (0)