Files
ComfyUI_frontend/browser_tests/fixtures/helpers/ToastHelper.ts
Johnpaul fb95fddf0d test: add toBeVisible assertions before every click in E2E tests
Adds `await expect(locator).toBeVisible()` before `.click()` calls
across 104 test and fixture files (431 assertions). Gives immediate,
descriptive failures instead of generic actionability timeouts.

Skips force clicks, canvas/mouse coordinate clicks, custom click
methods, catch chains, and toPass retry blocks. Updates
FLAKE_PREVENTION_RULES.md with the new rule.
2026-04-09 00:27:01 +01:00

41 lines
1.0 KiB
TypeScript

import { expect } from '@playwright/test'
import type { Locator, Page } from '@playwright/test'
export class ToastHelper {
constructor(private readonly page: Page) {}
get visibleToasts(): Locator {
return this.page.locator('.p-toast-message:visible')
}
async getToastErrorCount(): Promise<number> {
return await this.page
.locator('.p-toast-message.p-toast-message-error')
.count()
}
async getVisibleToastCount(): Promise<number> {
return await this.visibleToasts.count()
}
async closeToasts(requireCount = 0): Promise<void> {
if (requireCount) {
await this.visibleToasts
.nth(requireCount - 1)
.waitFor({ state: 'visible' })
}
// Clear all toasts
const toastCloseButtons = await this.page
.locator('.p-toast-close-button')
.all()
for (const button of toastCloseButtons) {
await expect(button).toBeVisible()
await button.click()
}
// Assert all toasts are closed
await expect(this.visibleToasts).toHaveCount(0, { timeout: 1000 })
}
}