-
-
Notifications
You must be signed in to change notification settings - Fork 493
[test] Add Guidepup screen reader tests #5328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { defineConfig, devices } from '@playwright/test'; | ||
| import { screenReaderConfig } from '@guidepup/playwright'; | ||
|
|
||
| const BASE_URL = 'http://localhost:5173'; | ||
|
|
||
| export default defineConfig({ | ||
| ...screenReaderConfig, | ||
| outputDir: '../../test-results/screen-reader', | ||
| testDir: '.', | ||
| testMatch: '*.spec.ts', | ||
| timeout: 60_000, | ||
| use: { | ||
| ...screenReaderConfig.use, | ||
| baseURL: BASE_URL, | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { | ||
| ...devices['Desktop Chrome'], | ||
| channel: process.env.CI ? 'chrome' : undefined, | ||
| }, | ||
| }, | ||
| ], | ||
| webServer: { | ||
| command: 'pnpm test:e2e:dev', | ||
| cwd: process.cwd(), | ||
| reuseExistingServer: !process.env.CI, | ||
| timeout: 120_000, | ||
| url: BASE_URL, | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { screenReaderTest as test, type ScreenReaderPlaywright } from '@guidepup/playwright'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| const MAX_NAVIGATION_STEPS = 10; | ||
|
|
||
| async function navigateToItem( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helper should be extracted as we see fit. |
||
| screenReader: ScreenReaderPlaywright, | ||
| name: RegExp, | ||
| step = 0, | ||
| ): Promise<string> { | ||
| const itemText = await screenReader.itemText(); | ||
|
|
||
| if (name.test(itemText)) { | ||
| return itemText; | ||
| } | ||
|
|
||
| if (step === MAX_NAVIGATION_STEPS) { | ||
| throw new Error(`Guidepup did not navigate to an item matching ${name}.`); | ||
| } | ||
|
|
||
| await screenReader.next(); | ||
| return navigateToItem(screenReader, name, step + 1); | ||
| } | ||
|
|
||
| test.use({ screenReaderStartOptions: { capture: true } }); | ||
|
|
||
| test("announces a radio option's accessible name", async ({ page, screenReader }) => { | ||
| await page.goto('/e2e-fixtures/Radio#no-dev'); | ||
| await page.locator('[data-testid="testcase"]:not([aria-busy="true"])').waitFor(); | ||
| await screenReader.navigateToWebContent(); | ||
|
|
||
| const itemText = await navigateToItem(screenReader, /fuji/i); | ||
| const spokenPhrase = await screenReader.lastSpokenPhrase(); | ||
|
|
||
| expect(itemText).toMatch(/fuji/i); | ||
| expect(spokenPhrase).toMatch(/fuji/i); | ||
| expect(spokenPhrase).toMatch(/radio/i); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be removed before merging.