import type { Locator } from 'playwright-core'; import { expect } from 'vitest'; /** * Assert that a Playwright locator is visible. * Waits up to 5 seconds for the element to become visible. */ export async function expectVisible(locator: Locator, timeout = 5000) { await locator.waitFor({ state: 'visible', timeout }); expect(await locator.isVisible()).toBe(true); } /** * Assert that a Playwright locator is NOT visible. * Waits briefly to ensure it doesn't appear. */ export async function expectNotVisible(locator: Locator, timeout = 2000) { try { await locator.waitFor({ state: 'hidden', timeout }); } catch { // Element may not exist at all, which is fine } expect(await locator.isVisible()).toBe(false); } /** * Assert that a locator has specific text content. */ export async function expectText(locator: Locator, text: string) { await locator.waitFor({ state: 'visible', timeout: 5000 }); expect(await locator.textContent()).toBe(text); } /** * Assert that a locator is disabled. */ export async function expectDisabled(locator: Locator) { await locator.waitFor({ state: 'visible', timeout: 5000 }); expect(await locator.isDisabled()).toBe(true); }