Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
IbrahimCSAE committed Dec 4, 2024
1 parent 58b06eb commit b88b87b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
12 changes: 10 additions & 2 deletions tests/3DFourUp.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions tests/3DMain.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions tests/3DOnly.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions tests/3DPrimary.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions tests/utils/attemptAction.ts
Original file line number Diff line number Diff line change
@@ -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<void>, 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));
}
}
};
2 changes: 2 additions & 0 deletions tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,4 +22,5 @@ export {
getTMTVModalityUnit,
clearAllAnnotations,
scrollVolumeViewport,
attemptAction,
};

0 comments on commit b88b87b

Please sign in to comment.