( page: AbstractWebPage, )
| 435 | } |
| 436 | |
| 437 | export function createWebInputPrimitives( |
| 438 | page: AbstractWebPage, |
| 439 | ): BrowserInputPrimitives { |
| 440 | const scheduleVisualUpdate = () => { |
| 441 | if (page.schedulePendingVisualUpdate) { |
| 442 | page.schedulePendingVisualUpdate(); |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | const pendingRefresh = page.flushPendingVisualUpdate?.(); |
| 447 | void pendingRefresh?.catch(() => undefined); |
| 448 | }; |
| 449 | |
| 450 | return { |
| 451 | pointer: { |
| 452 | tap: async ({ x, y }) => { |
| 453 | await page.mouse.click(x, y, { button: 'left' }); |
| 454 | }, |
| 455 | rightClick: async ({ x, y }) => { |
| 456 | await page.mouse.click(x, y, { button: 'right' }); |
| 457 | }, |
| 458 | doubleClick: async ({ x, y }) => { |
| 459 | await page.mouse.click(x, y, { button: 'left', count: 2 }); |
| 460 | }, |
| 461 | hover: async ({ x, y }) => { |
| 462 | await page.mouse.move(x, y); |
| 463 | }, |
| 464 | dragAndDrop: async (from, to) => { |
| 465 | await page.mouse.drag(from, to); |
| 466 | }, |
| 467 | longPress: async ({ x, y }, opts) => { |
| 468 | await page.longPress(x, y, opts?.duration); |
| 469 | }, |
| 470 | }, |
| 471 | keyboard: { |
| 472 | typeText: async (value, opts) => { |
| 473 | const element = opts?.target; |
| 474 | if (element && opts?.replace !== false) { |
| 475 | await page.clearInput(element as ElementInfo); |
| 476 | // Frameworks (React/Vue/etc.) often re-render in response to |
| 477 | // the `input` event fired by clearing. If that re-render lands |
| 478 | // between clearInput returning and the first typed character, |
| 479 | // the keypresses can be dropped. Wait for the DOM to settle |
| 480 | // before starting to type. |
| 481 | await page.waitForDomQuiet?.({ target: element as ElementInfo }); |
| 482 | } else if (element && opts?.focusOnly) { |
| 483 | const target = element as ElementInfo; |
| 484 | await page.mouse.click(target.center[0], target.center[1], { |
| 485 | button: 'left', |
| 486 | }); |
| 487 | await page.keyboard.press([{ key: 'End' }]); |
| 488 | } |
| 489 | |
| 490 | if (opts?.focusOnly) { |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | await page.keyboard.type(value); |
no test coverage detected