Skip to content

Commit 3d157f5

Browse files
authored
Merge pull request #3 from Romarionijim/feat/expand-functionality
Feat(e2e): add two generic functions to both basepage and app main page
2 parents 506a349 + 61060da commit 3d157f5

2 files changed

Lines changed: 35 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
}

pages/LumaMainPage.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export class LumaMainPage extends BasePage {
3030
private dialogFooterLocator = '[class="modal-footer"]';
3131
private loggedInAttributeLocator = '.logged-in';
3232
private accountDownArrowButtonLocator = '[class="panel header"] .customer-welcome'
33+
protected searchBarLocator = '#search';
34+
private searchResultList = '#search_autocomplete';
3335

3436
public async chooseMenuBarOption(menuBarItem: MenuBar) {
3537
let menuBarValue = this.page.locator(this.navigationMenuBar, { hasText: new RegExp(`^\\${menuBarItem.valueOf()}\\b$`, 'i') });
@@ -359,4 +361,19 @@ export class LumaMainPage extends BasePage {
359361
throw new Error(`user may be signed out and therefore the account options are not available`)
360362
}
361363
}
364+
365+
public async searchFor(item: string, options?: { pressEnter?: boolean }) {
366+
const searchBar = this.page.locator(this.searchBarLocator);
367+
await this.fillText(searchBar, item);
368+
if (options?.pressEnter) {
369+
await this.pressEnter();
370+
return;
371+
}
372+
const searchResults = this.page.locator(this.searchResultList);
373+
const searchResultVisiblity = await searchResults.isVisible();
374+
if (searchResultVisiblity) {
375+
const searchResultListItems = this.page.locator(this.searchResultList).locator('li');
376+
await this.clickAndChooseFromDropdownByText(this.searchBarLocator, searchResultListItems, item);
377+
}
378+
}
362379
}

0 commit comments

Comments
 (0)