|
| 1 | +import { log } from "../../log"; |
| 2 | +import { Page } from "@playwright/test"; |
| 3 | +import type { ScreenReaderPlaywright } from "../../../src"; |
| 4 | + |
| 5 | +const MAX_NAVIGATION_LOOP = 10; |
| 6 | + |
| 7 | +export async function delay(ms: number) { |
| 8 | + return new Promise((resolve) => setTimeout(resolve, ms)); |
| 9 | +} |
| 10 | + |
| 11 | +export async function headerNavigation({ |
| 12 | + page, |
| 13 | + screenReader, |
| 14 | +}: { |
| 15 | + page: Page; |
| 16 | + screenReader: ScreenReaderPlaywright; |
| 17 | +}) { |
| 18 | + // Navigate to Guidepup Website 🎉 |
| 19 | + log("Navigating to URL: https://www.guidepup.dev."); |
| 20 | + await page.goto("https://www.guidepup.dev", { |
| 21 | + waitUntil: "load", |
| 22 | + }); |
| 23 | + |
| 24 | + // Wait for page to be ready and interact 🙌 |
| 25 | + const header = page.locator("h1"); |
| 26 | + await header.waitFor(); |
| 27 | + await delay(500); |
| 28 | + |
| 29 | + // Make sure interacting with the web content |
| 30 | + await screenReader.navigateToWebContent(); |
| 31 | + await delay(500); |
| 32 | + |
| 33 | + let navigationCount = 0; |
| 34 | + |
| 35 | + // Move across the content |
| 36 | + while ( |
| 37 | + !(await screenReader.itemText()).replaceAll(/\s/g, "").includes("GitHub") && |
| 38 | + navigationCount <= MAX_NAVIGATION_LOOP |
| 39 | + ) { |
| 40 | + navigationCount++; |
| 41 | + |
| 42 | + log(`Performing command: next`); |
| 43 | + await screenReader.next(); |
| 44 | + log(`Screen reader output: "${await screenReader.lastSpokenPhrase()}".`); |
| 45 | + } |
| 46 | + |
| 47 | + log(`Performing command: act`); |
| 48 | + await screenReader.act(); |
| 49 | + log(`Screen reader output: "${await screenReader.lastSpokenPhrase()}".`); |
| 50 | +} |
0 commit comments