import { expect } from '@playwright/test'; export class AssertionHelper { async assertElementVisible(page: Page, selector: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toBeVisible(); } async assertElementHidden(page: Page, selector: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toBeHidden(); } async assertElementText(page: Page, selector: string, expectedText: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toHaveText(expectedText); } async assertElementContainsText(page: Page, selector: string, expectedText: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toContainText(expectedText); } async assertElementValue(page: Page, selector: string, expectedValue: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toHaveValue(expectedValue); } async assertElementEnabled(page: Page, selector: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toBeEnabled(); } async assertElementDisabled(page: Page, selector: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toBeDisabled(); } async assertElementChecked(page: Page, selector: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toBeChecked(); } async assertElementCount(page: Page, selector: string, expectedCount: number, message?: string): Promise { const elements = page.locator(selector); const count = await elements.count(); expect(count, message).toBe(expectedCount); } async assertElementCountGreaterThan(page: Page, selector: string, minCount: number, message?: string): Promise { const elements = page.locator(selector); const count = await elements.count(); expect(count, message).toBeGreaterThan(minCount); } async assertElementCountLessThan(page: Page, selector: string, maxCount: number, message?: string): Promise { const elements = page.locator(selector); const count = await elements.count(); expect(count, message).toBeLessThan(maxCount); } async assertURL(page: Page, expectedURL: string | RegExp, message?: string): Promise { await expect(page, message).toHaveURL(expectedURL); } async assertTitle(page: Page, expectedTitle: string, message?: string): Promise { await expect(page, message).toHaveTitle(expectedTitle); } async assertAttributeValue(page: Page, selector: string, attribute: string, expectedValue: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toHaveAttribute(attribute, expectedValue); } async assertCSSClass(page: Page, selector: string, className: string, message?: string): Promise { const element = page.locator(selector); await expect(element, message).toHaveClass(new RegExp(className)); } async assertAPISuccess(response: APIResponse, message?: string): Promise { expect(response.status(), message).toBe(200); const body = await response.json(); expect(body.code, message).toBe('200'); } async assertAPIResponseCode(response: APIResponse, expectedCode: string, message?: string): Promise { const body = await response.json(); expect(body.code, message).toBe(expectedCode); } async assertAPIResponseData(response: APIResponse, expectedData: any, message?: string): Promise { const body = await response.json(); expect(body.data, message).toEqual(expectedData); } async assertTableData(page: Page, tableSelector: string, expectedData: any[][], message?: string): Promise { const tableHelper = new TableHelper(page); const isValid = await tableHelper.validateTableData(tableSelector, expectedData); expect(isValid, message).toBe(true); } async assertFormValid(page: Page, message?: string): Promise { const formHelper = new FormHelper(page); const isValid = await formHelper.validateForm(); expect(isValid, message).toBe(true); } async assertFormInvalid(page: Page, message?: string): Promise { const formHelper = new FormHelper(page); const isValid = await formHelper.validateForm(); expect(isValid, message).toBe(false); } async assertSuccessMessage(page: Page, message?: string): Promise { const successElement = page.locator('.success-message, .ant-message-success'); await expect(successElement, message).toBeVisible(); } async assertErrorMessage(page: Page, expectedMessage?: string, message?: string): Promise { const errorElement = page.locator('.error-message, .ant-message-error'); await expect(errorElement, message).toBeVisible(); if (expectedMessage) { await expect(errorElement, message).toContainText(expectedMessage); } } async assertLoading(page: Page, message?: string): Promise { const loadingElement = page.locator('.loading, .ant-spin, .loading-indicator'); await expect(loadingElement, message).toBeVisible(); } async assertNotLoading(page: Page, message?: string): Promise { const loadingElement = page.locator('.loading, .ant-spin, .loading-indicator'); await expect(loadingElement, message).toBeHidden(); } async assertModalVisible(page: Page, message?: string): Promise { const modalElement = page.locator('.modal, .ant-modal, .dialog'); await expect(modalElement, message).toBeVisible(); } async assertModalHidden(page: Page, message?: string): Promise { const modalElement = page.locator('.modal, .ant-modal, .dialog'); await expect(modalElement, message).toBeHidden(); } async assertToastVisible(page: Page, message?: string): Promise { const toastElement = page.locator('.toast, .ant-message'); await expect(toastElement, message).toBeVisible(); } async assertToastHidden(page: Page, message?: string): Promise { const toastElement = page.locator('.toast, .ant-message'); await expect(toastElement, message).toBeHidden(); } }