26
test/helpers/e2e/assertElementStaysVisible.ts
Normal file
26
test/helpers/e2e/assertElementStaysVisible.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { Page } from 'playwright'
|
||||
|
||||
export async function assertElementStaysVisible(
|
||||
page: Page,
|
||||
selector: string,
|
||||
durationMs: number = 3000,
|
||||
pollIntervalMs: number = 250,
|
||||
): Promise<void> {
|
||||
const start = Date.now()
|
||||
|
||||
// Ensure it appears at least once first
|
||||
await page.waitForSelector(selector, { state: 'visible' })
|
||||
|
||||
// Start polling to confirm it stays visible
|
||||
while (Date.now() - start < durationMs) {
|
||||
const isVisible = await page.isVisible(selector)
|
||||
|
||||
if (!isVisible) {
|
||||
throw new Error(`Element "${selector}" disappeared during the visibility duration.`)
|
||||
}
|
||||
|
||||
await new Promise((res) => setTimeout(res, pollIntervalMs))
|
||||
}
|
||||
|
||||
console.log(`Element "${selector}" remained visible for ${durationMs}ms.`)
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import { expect } from '@playwright/test'
|
||||
export const assertRequestBody = async <T>(
|
||||
page: Page,
|
||||
options: {
|
||||
action: Promise<void> | void
|
||||
action: () => Promise<void> | void
|
||||
expect?: (requestBody: T) => boolean | Promise<boolean>
|
||||
requestMethod?: string
|
||||
url: string
|
||||
@@ -34,7 +34,7 @@ export const assertRequestBody = async <T>(
|
||||
(request.method() === options.requestMethod || 'POST'),
|
||||
),
|
||||
),
|
||||
await options.action,
|
||||
await options.action(),
|
||||
])
|
||||
|
||||
const requestBody = request.postData()
|
||||
|
||||
Reference in New Issue
Block a user