Files
payload/test/helpers/e2e/assertElementStaysVisible.ts
Jacob Fletcher bd557a97d5 test: optimistic form state rows (#12055)
Adds tests for #11961.
2025-04-08 20:56:24 -06:00

27 lines
749 B
TypeScript

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.`)
}