import type { Locator, Page } from '@playwright/test' export class KeyboardHelper { constructor( private readonly page: Page, private readonly canvas: Locator ) {} private async nextFrame(): Promise { await this.page.evaluate(() => new Promise(requestAnimationFrame)) } async ctrlSend( keyToPress: string, locator: Locator | null = this.canvas ): Promise { const target = locator ?? this.page.keyboard await target.press(`Control+${keyToPress}`) await this.nextFrame() } async selectAll(locator?: Locator | null): Promise { await this.ctrlSend('KeyA', locator) } async bypass(locator?: Locator | null): Promise { await this.ctrlSend('KeyB', locator) } async undo(locator?: Locator | null): Promise { await this.ctrlSend('KeyZ', locator) } async redo(locator?: Locator | null): Promise { await this.ctrlSend('KeyY', locator) } async moveUp(locator?: Locator | null): Promise { await this.ctrlSend('ArrowUp', locator) } async moveDown(locator?: Locator | null): Promise { await this.ctrlSend('ArrowDown', locator) } }