tests(Playwright): Introduction of Page Object Models (POMs) to Playwright tests (#5557)

This commit is contained in:
Vinícius Alves de Faria Resende authored and GitHub committed 2025-11-20 09:29:14 -05:00
1 parent 1c991037ee
commit bdad2264ed
59 files changed
+1040 -756

No files matched your search

+21 -18
View File
@@ -1,7 +1,7 @@
import { test, expect } from 'playwright-test-coverage';
import { Page } from '@playwright/test';
import { visitStudy, checkForScreenshot, screenShotPaths } from './utils';
import { ViewportPageObject } from './pages';
import { checkForScreenshot, expect, screenShotPaths, test, visitStudy } from './utils';
import { press } from './utils/keyboardUtils';
test.beforeEach(async ({ page }) => {
@@ -15,13 +15,16 @@ test.beforeEach(async ({ page }) => {
await page.waitForTimeout(500);
});
async function performDrawingToolInteraction(page: Page, toolName: string) {
async function performDrawingToolInteraction(
page: Page,
toolName: string,
viewportPageObject: ViewportPageObject
) {
const brushRadiusInput = page.getByTestId(`${toolName}-radius`).locator('input');
const viewportGrid = page.getByTestId('viewport-grid');
const circle = viewportGrid.locator('svg.svg-layer circle').first();
const circle = viewportPageObject.active.svg('circle').first();
await expect(brushRadiusInput).toHaveValue('25');
await viewportGrid.click({ position: { x: 275, y: 300 } });
await viewportPageObject.active.clickAt([{ x: 275, y: 300 }]);
let radius = parseFloat(await circle.getAttribute('r'));
expect(radius).toBeGreaterThanOrEqual(65);
expect(radius).toBeLessThanOrEqual(68);
@@ -29,7 +32,7 @@ async function performDrawingToolInteraction(page: Page, toolName: string) {
await page.waitForTimeout(500);
await press({ page, key: '[', nTimes: 2 });
await expect(brushRadiusInput).toHaveValue('19');
await viewportGrid.click({ position: { x: 500, y: 300 } });
await viewportPageObject.active.clickAt([{ x: 500, y: 300 }]);
radius = parseFloat(await circle.getAttribute('r'));
expect(radius).toBeGreaterThanOrEqual(49);
expect(radius).toBeLessThanOrEqual(52);
@@ -38,7 +41,7 @@ async function performDrawingToolInteraction(page: Page, toolName: string) {
await press({ page, key: ']', nTimes: 5 });
await expect(brushRadiusInput).toHaveValue('34');
await viewportGrid.click({ position: { x: 275, y: 500 } });
await viewportPageObject.active.clickAt([{ x: 275, y: 500 }]);
radius = parseFloat(await circle.getAttribute('r'));
expect(radius).toBeGreaterThanOrEqual(87);
expect(radius).toBeLessThanOrEqual(90);
@@ -46,7 +49,7 @@ async function performDrawingToolInteraction(page: Page, toolName: string) {
await page.waitForTimeout(500);
await brushRadiusInput.fill('42');
await viewportGrid.click({ position: { x: 500, y: 500 } });
await viewportPageObject.active.clickAt([{ x: 500, y: 500 }]);
radius = parseFloat(await circle.getAttribute('r'));
expect(radius).toBeGreaterThanOrEqual(108);
expect(radius).toBeLessThanOrEqual(111);
@@ -54,23 +57,23 @@ async function performDrawingToolInteraction(page: Page, toolName: string) {
await page.waitForTimeout(500);
}
test('(shouldUpdateThis) should resize segmentation brush tool', async ({ page }) => {
test('should resize segmentation brush tool', async ({ page, viewportPageObject }) => {
await page.getByTestId('Brush-btn').click();
await performDrawingToolInteraction(page, 'brush');
await performDrawingToolInteraction(page, 'brush', viewportPageObject);
await checkForScreenshot(
page,
page.getByTestId('viewport-grid'),
viewportPageObject.active.pane,
screenShotPaths.segDrawingToolsResizing.brushTool
);
});
test('(shouldUpdateThis) should resize segmentation eraser tool', async ({ page }) => {
test('should resize segmentation eraser tool', async ({ page, viewportPageObject }) => {
await page.getByTestId('Brush-btn').click();
await page.getByTestId('brush-radius').locator('input').fill('99.5');
await page.getByTestId('viewport-grid').click({ position: { x: 400, y: 400 } });
await viewportPageObject.active.clickAt([{ x: 400, y: 400 }]);
await page.waitForTimeout(500);
@@ -79,17 +82,17 @@ test('(shouldUpdateThis) should resize segmentation eraser tool', async ({ page
await page.waitForTimeout(500);
await performDrawingToolInteraction(page, 'eraser');
await performDrawingToolInteraction(page, 'eraser', viewportPageObject);
await checkForScreenshot(
page,
page.getByTestId('viewport-grid'),
viewportPageObject.active.pane,
screenShotPaths.segDrawingToolsResizing.eraserTool
);
});
test('(shouldUpdateThis) should resize segmentation threshold tool', async ({ page }) => {
test('should resize segmentation threshold tool', async ({ page, viewportPageObject }) => {
await page.getByTestId('Threshold-btn').click();
await performDrawingToolInteraction(page, 'threshold');
await performDrawingToolInteraction(page, 'threshold', viewportPageObject);
});