From 7e50c72fbbf466d1b050d5f28a210758a167d2b9 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Sat, 28 Jan 2023 17:12:07 +0530 Subject: [PATCH] test: cell selection retry logic to avoid flakyness Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- .../playwright/pages/Dashboard/Grid/index.ts | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/tests/playwright/pages/Dashboard/Grid/index.ts b/tests/playwright/pages/Dashboard/Grid/index.ts index 745d5ba1a9..9e3f3b507b 100644 --- a/tests/playwright/pages/Dashboard/Grid/index.ts +++ b/tests/playwright/pages/Dashboard/Grid/index.ts @@ -308,18 +308,41 @@ export class GridPage extends BasePage { } async copyWithKeyboard() { - await this.get().press((await this.isMacOs()) ? 'Meta+C' : 'Control+C'); - await this.verifyToast({ message: 'Copied to clipboard' }); - - return this.getClipboardText(); + // retry to avoid flakiness, until text is copied to clipboard + // + let text = ''; + let retryCount = 5; + while (text === '') { + await this.get().press((await this.isMacOs()) ? 'Meta+C' : 'Control+C'); + await this.verifyToast({ message: 'Copied to clipboard' }); + text = await this.getClipboardText(); + + // retry if text is empty till count is reached + retryCount--; + if (0 === retryCount) { + break; + } + } + return text; } async copyWithMouse({ index, columnHeader }: CellProps) { - await this.cell.get({ index, columnHeader }).click({ button: 'right' }); - await this.get().page().getByTestId('context-menu-item-copy').click(); - - await this.verifyToast({ message: 'Copied to clipboard' }); - - return this.getClipboardText(); + // retry to avoid flakiness, until text is copied to clipboard + // + let text = ''; + let retryCount = 5; + while (text === '') { + await this.cell.get({ index, columnHeader }).click({ button: 'right' }); + await this.get().page().getByTestId('context-menu-item-copy').click(); + await this.verifyToast({ message: 'Copied to clipboard' }); + text = await this.getClipboardText(); + + // retry if text is empty till count is reached + retryCount--; + if (0 === retryCount) { + break; + } + } + return text; } }