From b88b87b32c7aeefe9489e6dece750e4a84d21948 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Wed, 4 Dec 2024 13:52:51 -0500 Subject: [PATCH] stuff --- tests/3DFourUp.spec.ts | 12 ++++++++++-- tests/3DMain.spec.ts | 10 ++++++++-- tests/3DOnly.spec.ts | 10 ++++++++-- tests/3DPrimary.spec.ts | 10 ++++++++-- tests/utils/attemptAction.ts | 21 +++++++++++++++++++++ tests/utils/index.ts | 2 ++ 6 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tests/utils/attemptAction.ts diff --git a/tests/3DFourUp.spec.ts b/tests/3DFourUp.spec.ts index e196856d9ca..f54e8c2fc6b 100644 --- a/tests/3DFourUp.spec.ts +++ b/tests/3DFourUp.spec.ts @@ -1,5 +1,11 @@ import { test } from '@playwright/test'; -import { visitStudy, checkForScreenshot, screenShotPaths, reduce3DViewportSize } from './utils'; +import { + visitStudy, + checkForScreenshot, + screenShotPaths, + reduce3DViewportSize, + attemptAction, +} from './utils'; test.beforeEach(async ({ page }) => { const studyInstanceUID = '1.3.6.1.4.1.14519.5.2.1.1706.8374.643249677828306008300337414785'; @@ -15,7 +21,9 @@ test.describe('3D four up Test', async () => { .filter({ hasText: /^3D four up$/ }) .first() .click(); - await reduce3DViewportSize(page); + + await attemptAction(() => reduce3DViewportSize(page), 10, 100); + await checkForScreenshot( page, page, diff --git a/tests/3DMain.spec.ts b/tests/3DMain.spec.ts index f0ce18f34aa..84164e93a44 100644 --- a/tests/3DMain.spec.ts +++ b/tests/3DMain.spec.ts @@ -1,5 +1,11 @@ import { test } from '@playwright/test'; -import { visitStudy, checkForScreenshot, screenShotPaths, reduce3DViewportSize } from './utils'; +import { + visitStudy, + checkForScreenshot, + screenShotPaths, + reduce3DViewportSize, + attemptAction, +} from './utils'; test.beforeEach(async ({ page }) => { const studyInstanceUID = '1.3.6.1.4.1.14519.5.2.1.1706.8374.643249677828306008300337414785'; @@ -15,7 +21,7 @@ test.describe('3D main Test', async () => { .filter({ hasText: /^3D main$/ }) .first() .click(); - await reduce3DViewportSize(page); + await attemptAction(() => reduce3DViewportSize(page), 10, 100); await checkForScreenshot( page, page, diff --git a/tests/3DOnly.spec.ts b/tests/3DOnly.spec.ts index 28489d02477..0f2905834ab 100644 --- a/tests/3DOnly.spec.ts +++ b/tests/3DOnly.spec.ts @@ -1,5 +1,11 @@ import { test } from '@playwright/test'; -import { visitStudy, checkForScreenshot, screenShotPaths, reduce3DViewportSize } from './utils'; +import { + visitStudy, + checkForScreenshot, + screenShotPaths, + reduce3DViewportSize, + attemptAction, +} from './utils'; test.beforeEach(async ({ page }) => { const studyInstanceUID = '1.3.6.1.4.1.14519.5.2.1.1706.8374.643249677828306008300337414785'; @@ -15,7 +21,7 @@ test.describe('3D only Test', async () => { .filter({ hasText: /^3D only$/ }) .first() .click(); - await reduce3DViewportSize(page); + await attemptAction(() => reduce3DViewportSize(page), 10, 100); await checkForScreenshot( page, page, diff --git a/tests/3DPrimary.spec.ts b/tests/3DPrimary.spec.ts index f384815884a..4b9bb335b67 100644 --- a/tests/3DPrimary.spec.ts +++ b/tests/3DPrimary.spec.ts @@ -1,5 +1,11 @@ import { test } from '@playwright/test'; -import { visitStudy, checkForScreenshot, screenShotPaths, reduce3DViewportSize } from './utils'; +import { + visitStudy, + checkForScreenshot, + screenShotPaths, + reduce3DViewportSize, + attemptAction, +} from './utils'; test.beforeEach(async ({ page }) => { const studyInstanceUID = '1.3.6.1.4.1.14519.5.2.1.1706.8374.643249677828306008300337414785'; @@ -16,7 +22,7 @@ test.describe('3D primary Test', async () => { .first() .click(); - await reduce3DViewportSize(page); + await attemptAction(() => reduce3DViewportSize(page), 10, 100); await checkForScreenshot( page, page, diff --git a/tests/utils/attemptAction.ts b/tests/utils/attemptAction.ts new file mode 100644 index 00000000000..d9ea5c05bdc --- /dev/null +++ b/tests/utils/attemptAction.ts @@ -0,0 +1,21 @@ +/** + * + * @param action The action function to attempt + * @param attempts The number of attempts to try the action + * @param delay delay between attempts + * @returns True if the action is successful, otherwise throws an error + */ + +export const attemptAction = async (action: () => Promise, attempts = 10, delay = 100) => { + for (let i = 1; i < attempts; i++) { + try { + await action(); + return true; + } catch (error) { + if (i === attempts) { + throw new Error('Action failed.'); + } + await new Promise(resolve => setTimeout(resolve, delay)); + } + } +}; diff --git a/tests/utils/index.ts b/tests/utils/index.ts index ff5acf51047..ddfe4bcac35 100644 --- a/tests/utils/index.ts +++ b/tests/utils/index.ts @@ -8,6 +8,7 @@ import { getSUV } from './getSUV'; import { getTMTVModalityUnit } from './getTMTVModalityUnit'; import { clearAllAnnotations } from './clearAllAnnotations'; import { scrollVolumeViewport } from './scrollVolumeViewport'; +import { attemptAction } from './attemptAction'; export { visitStudy, @@ -21,4 +22,5 @@ export { getTMTVModalityUnit, clearAllAnnotations, scrollVolumeViewport, + attemptAction, };