import { Page } from "@playwright/test"; import { getByTestId, getButtonByText } from "./elements"; /** * Click an element by its data-testid attribute */ export async function clickElement(page: Page, testId: string): Promise { const element = await getByTestId(page, testId); await element.click(); } /** * Click a button by its text content */ export async function clickButtonByText( page: Page, text: string ): Promise { const button = await getButtonByText(page, text); await button.click(); } /** * Fill an input field by its data-testid attribute */ export async function fillInput( page: Page, testId: string, value: string ): Promise { const input = await getByTestId(page, testId); await input.fill(value); } /** * Press a keyboard shortcut key */ export async function pressShortcut(page: Page, key: string): Promise { await page.keyboard.press(key); } /** * Press a number key (0-9) on the keyboard */ export async function pressNumberKey(page: Page, num: number): Promise { await page.keyboard.press(num.toString()); } /** * Focus on an input element to test that shortcuts don't fire when typing */ export async function focusOnInput(page: Page, testId: string): Promise { const input = page.locator(`[data-testid="${testId}"]`); await input.focus(); } /** * Close any open dialog by pressing Escape */ export async function closeDialogWithEscape(page: Page): Promise { await page.keyboard.press("Escape"); await page.waitForTimeout(100); // Give dialog time to close }