Skip to content

Commit 998b2a3

Browse files
committed
Add interactWhenVisible safe waiting
1 parent dd8fd99 commit 998b2a3

1 file changed

Lines changed: 30 additions & 43 deletions

File tree

e2e/logic/POM/codeGraph.ts

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export default class CodeGraph extends BasePage {
266266
await this.page.waitForLoadState('networkidle');
267267
const [newPage] = await Promise.all([
268268
this.page.waitForEvent('popup'),
269-
this.falkorDBLogo.click(),
269+
interactWhenVisible(this.falkorDBLogo, (el) => el.click(), 'FalkorDB Logo'),
270270
]);
271271
return newPage
272272
}
@@ -275,23 +275,21 @@ export default class CodeGraph extends BasePage {
275275
await this.page.waitForLoadState('networkidle');
276276
const [newPage] = await Promise.all([
277277
this.page.waitForEvent('popup'),
278-
this.navBaritem(navItem).click(),
278+
interactWhenVisible(this.navBaritem(navItem), (el) => el.click(), `NavBar item: ${navItem}`),
279279
]);
280280
return newPage
281281
}
282282

283283
async clickCreateNewProjectBtn(): Promise<void> {
284-
const isVisible = await waitForElementToBeVisible(this.createNewProjectBtn);
285-
if (!isVisible) throw new Error("'Create New Project' button is not visible!");
286-
await this.createNewProjectBtn.click();
284+
await interactWhenVisible(this.createNewProjectBtn, (el) => el.click(), 'Create New Project button');
287285
}
288286

289287
async isCreateNewProjectDialog(): Promise<boolean> {
290288
return await waitForElementToBeVisible(this.createNewProjectDialog);
291289
}
292290

293291
async clickOnTipBtn(): Promise<void> {
294-
await this.tipBtn.click();
292+
await interactWhenVisible(this.tipBtn, (el) => el.click(), 'Tip button');
295293
}
296294

297295
async isTipMenuVisible(): Promise<boolean> {
@@ -300,31 +298,27 @@ export default class CodeGraph extends BasePage {
300298
}
301299

302300
async clickOnTipMenuCloseBtn(): Promise<void> {
303-
const isVisible = await waitForElementToBeVisible(this.tipMenuCloseBtn);
304-
if (!isVisible) throw new Error("'Tip Menu Close' button is not visible!");
305-
await this.tipMenuCloseBtn.click();
301+
await interactWhenVisible(this.tipMenuCloseBtn, (el) => el.click(), 'Tip Menu Close button');
306302
}
307303

308304

309305
/* Chat functionality */
310306
async clickOnShowPathBtn(selection: string): Promise<void> {
311-
await this.showPathBtn(selection).click();
307+
await interactWhenVisible(this.showPathBtn(selection), (el) => el.click(), `Show Path button: ${selection}`);
312308
}
313309

314310
async clickAskQuestionBtn(): Promise<void> {
315-
const isVisible = await waitForElementToBeVisible(this.askquestionBtn);
316-
if (!isVisible) throw new Error("'Ask Question' button is not visible!");
317-
await this.askquestionBtn.click();
311+
await interactWhenVisible(this.askquestionBtn, (el) => el.click(), 'Ask Question button');
318312
}
319313

320314
async sendMessage(message: string) {
321315
await waitToBeEnabled(this.askquestionBtn);
322-
await this.askquestionInput.fill(message);
323-
await this.askquestionBtn.click();
316+
await interactWhenVisible(this.askquestionInput, (el) => el.fill(message), 'Ask question input');
317+
await interactWhenVisible(this.askquestionBtn, (el) => el.click(), 'Ask Question button');
324318
}
325319

326320
async clickOnLightBulbBtn(): Promise<void> {
327-
await this.lightbulbBtn.click();
321+
await interactWhenVisible(this.lightbulbBtn, (el) => el.click(), 'Light Bulb button');
328322
}
329323

330324
async getTextInLastChatElement(): Promise<string> {
@@ -366,8 +360,8 @@ export default class CodeGraph extends BasePage {
366360
}
367361

368362
async insertInputForShowPath(inputNum: string, node: string): Promise<void> {
369-
await this.selectInputForShowPath(inputNum).fill(node);
370-
await this.selectFirstPathOption(inputNum).click();
363+
await interactWhenVisible(this.selectInputForShowPath(inputNum), (el) => el.fill(node), `Path input ${inputNum}`);
364+
await interactWhenVisible(this.selectFirstPathOption(inputNum), (el) => el.click(), `Path option ${inputNum}`);
371365
}
372366

373367
async isNodeVisibleInLastChatPath(node: string): Promise<boolean> {
@@ -382,15 +376,14 @@ export default class CodeGraph extends BasePage {
382376
}
383377

384378
async clickOnNotificationErrorCloseBtn(): Promise<void> {
385-
const isVisible = await waitForElementToBeVisible(this.notificationErrorCloseBtn);
386-
if (!isVisible) throw new Error("Notification error close button is not visible!");
387-
await this.notificationErrorCloseBtn.click();
379+
await interactWhenVisible(this.notificationErrorCloseBtn, (el) => el.click(), 'Notification Error Close button');
388380
}
389381

390382
async selectAndGetQuestionInOptionsMenu(questionNumber: string): Promise<string> {
391383
const question = this.selectQuestionInMenu(questionNumber);
392-
await question.click();
393-
return await question.innerText();
384+
const text = await question.innerText();
385+
await interactWhenVisible(question, (el) => el.click(), `Question option ${questionNumber}`);
386+
return text;
394387
}
395388

396389
async getLastQuestionInChat(): Promise<string> {
@@ -401,35 +394,33 @@ export default class CodeGraph extends BasePage {
401394

402395
/* CodeGraph functionality */
403396
async selectGraph(graph: string | number): Promise<void> {
404-
await this.comboBoxbtn.click();
397+
await interactWhenVisible(this.comboBoxbtn, (el) => el.click(), 'ComboBox button');
405398
if (typeof graph === 'number') {
406-
await this.selectGraphInComboBoxById(graph.toString()).waitFor({ state: 'visible' })
407-
await this.selectGraphInComboBoxById(graph.toString()).click();
399+
await interactWhenVisible(this.selectGraphInComboBoxById(graph.toString()), (el) => el.click(), `Graph option ${graph}`);
408400
} else {
409-
await this.selectGraphInComboBoxByName(graph).waitFor({ state: 'visible' })
410-
await this.selectGraphInComboBoxByName(graph).click();
401+
await interactWhenVisible(this.selectGraphInComboBoxByName(graph), (el) => el.click(), `Graph option ${graph}`);
411402
}
412403
await this.page.waitForTimeout(2000); // graph animation delay
413404
}
414405

415406
async createProject(url: string): Promise<void> {
416407
await this.clickCreateNewProjectBtn();
417-
await this.typeUrlInput.fill(url);
418-
await this.createBtnInCreateProjectDialog.click();
408+
await interactWhenVisible(this.typeUrlInput, (el) => el.fill(url), 'URL input');
409+
await interactWhenVisible(this.createBtnInCreateProjectDialog, (el) => el.click(), 'Create button');
419410
await this.createProjectWaitDialog.waitFor({ state: 'hidden' });
420411
}
421412

422413
async isGraphCreated(graph: string): Promise<boolean> {
423-
await this.comboBoxbtn.click();
414+
await interactWhenVisible(this.comboBoxbtn, (el) => el.click(), 'ComboBox button');
424415
return await this.dialogCreatedGraphsList(graph).isVisible();
425416
}
426417

427418
async fillSearchBar(searchValue: string): Promise<void> {
428-
await this.searchBarInput.fill(searchValue);
419+
await interactWhenVisible(this.searchBarInput, (el) => el.fill(searchValue), 'Search bar input');
429420
}
430421

431422
async getSearchAutoCompleteCount(): Promise<number> {
432-
await this.searchBarAutoCompleteOptions.first().waitFor({ state: 'visible' });
423+
await interactWhenVisible(this.searchBarAutoCompleteOptions.first(), async () => {}, 'Search auto-complete options');
433424
return await this.searchBarAutoCompleteOptions.count();
434425
}
435426

@@ -438,9 +429,7 @@ export default class CodeGraph extends BasePage {
438429
}
439430

440431
async selectSearchBarOptionBtn(buttonNum: string): Promise<void> {
441-
const button = this.searchBarOptionBtn(buttonNum);
442-
await button.waitFor({ state: "visible" })
443-
await button.click();
432+
await interactWhenVisible(this.searchBarOptionBtn(buttonNum), (el) => el.click(), `Search bar option ${buttonNum}`);
444433
}
445434

446435
async getSearchBarInputValue(): Promise<string | null> {
@@ -501,12 +490,12 @@ export default class CodeGraph extends BasePage {
501490

502491

503492
async selectCodeGraphCheckbox(checkbox: string): Promise<void> {
504-
await this.codeGraphCheckbox(checkbox).click();
493+
await interactWhenVisible(this.codeGraphCheckbox(checkbox), (el) => el.click(), `Checkbox ${checkbox}`);
505494
}
506495

507496
async clickOnClearGraphBtn(): Promise<void> {
508497
await this.page.mouse.click(10, 10);
509-
await this.clearGraphBtn.click();
498+
await interactWhenVisible(this.clearGraphBtn, (el) => el.click(), 'Clear Graph button');
510499
}
511500

512501
async clickOnUnhideNodesBtn(): Promise<void> {
@@ -563,7 +552,7 @@ export default class CodeGraph extends BasePage {
563552
}
564553

565554
async clickOnNodeDetailsCloseBtn(): Promise<void> {
566-
await this.nodedetailsPanelcloseBtn.click();
555+
await interactWhenVisible(this.nodedetailsPanelcloseBtn, (el) => el.click(), 'Node Details Close button');
567556
}
568557

569558
async getMetricsPanelInfo(): Promise<{ nodes: string, edges: string }> {
@@ -573,9 +562,7 @@ export default class CodeGraph extends BasePage {
573562
}
574563

575564
async clickOnCopyToClipboardNodePanelDetails(): Promise<string> {
576-
const isButtonVisible = await waitForElementToBeVisible(this.copyToClipboardNodePanelDetails);
577-
if (!isButtonVisible) throw new Error("'copy to clipboard button is not visible!");
578-
await this.copyToClipboardNodePanelDetails.click();
565+
await interactWhenVisible(this.copyToClipboardNodePanelDetails, (el) => el.click(), 'Copy to clipboard button');
579566
return await this.page.evaluate(() => navigator.clipboard.readText());
580567
}
581568

@@ -677,7 +664,7 @@ export default class CodeGraph extends BasePage {
677664
await this.page.waitForLoadState('networkidle');
678665
const [download] = await Promise.all([
679666
this.page.waitForEvent('download'),
680-
this.downloadImageBtn.click(),
667+
interactWhenVisible(this.downloadImageBtn, (el) => el.click(), 'Download Image button'),
681668
]);
682669

683670
return download;

0 commit comments

Comments
 (0)