From 896eba95a4e543276ffb60ed6124e91bb2431000 Mon Sep 17 00:00:00 2001 From: jlp-craigmorten Date: Thu, 25 Jul 2024 16:03:09 +0100 Subject: [PATCH 1/2] feat: allow setting of start options --- .gitignore | 1 + README.md | 20 ++++++++++++++++++- .../tests/chromium/chromium.spec.ts | 2 ++ .../tests/firefox/firefox.spec.ts | 2 ++ .../tests/chromium/chromium.spec.ts | 2 ++ .../tests/firefox/firefox.spec.ts | 2 ++ .../tests/webkit/webkit.spec.ts | 2 ++ src/nvdaTest.ts | 19 +++++++++++++++--- src/voiceOverTest.ts | 13 +++++++++--- 9 files changed, 56 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 67d3f2a..f9703ad 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,4 @@ dist lib .DS_Store test-results +recordings diff --git a/README.md b/README.md index dce01d1..883f067 100644 --- a/README.md +++ b/README.md @@ -110,12 +110,30 @@ await nvda.navigateToWebContent(); // ... some commands -// Collect all spoken phrasees +// Collect all spoken phrases const allSpokenPhrases = [...spokenPhrases, ...(await nvda.spokenPhraseLog())]; // ... do something with spoken phrases ``` +### Providing Screen Reader Start Options + +The options provided to `nvda.start([options])` or `voiceOver.start([options])` can be configured using `test.use(config)` as follows: + +```ts +// VoiceOver Example +import { voiceOverTest as test } from "@guidepup/playwright"; + +test.use({ voiceOverStartOptions: { capture: "initial" } }); +``` + +```ts +// NVDA Example +import { nvdaTest as test } from "@guidepup/playwright"; + +test.use({ nvdaStartOptions: { capture: "initial" } }); +``` + ### VoiceOver Example `playwright.config.ts`: diff --git a/examples/playwright-nvda/tests/chromium/chromium.spec.ts b/examples/playwright-nvda/tests/chromium/chromium.spec.ts index 377f145..0761319 100644 --- a/examples/playwright-nvda/tests/chromium/chromium.spec.ts +++ b/examples/playwright-nvda/tests/chromium/chromium.spec.ts @@ -5,6 +5,8 @@ import { windowsRecord } from "@guidepup/guidepup"; import spokenPhraseSnapshot from "./chromium.spokenPhrase.snapshot.json"; import { nvdaTest as test } from "../../../../src"; +test.use({ nvdaStartOptions: { capture: "initial" } }); + test.describe("Chromium Playwright NVDA", () => { test("I can navigate the Guidepup Github page", async ({ browser, diff --git a/examples/playwright-nvda/tests/firefox/firefox.spec.ts b/examples/playwright-nvda/tests/firefox/firefox.spec.ts index d6a4b3e..e21b12e 100644 --- a/examples/playwright-nvda/tests/firefox/firefox.spec.ts +++ b/examples/playwright-nvda/tests/firefox/firefox.spec.ts @@ -5,6 +5,8 @@ import { windowsRecord } from "@guidepup/guidepup"; import spokenPhraseSnapshot from "./firefox.spokenPhrase.snapshot.json"; import { nvdaTest as test } from "../../../../src"; +test.use({ nvdaStartOptions: { capture: "initial" } }); + test.describe("Firefox Playwright VoiceOver", () => { test("I can navigate the Guidepup Github page", async ({ browser, diff --git a/examples/playwright-voiceover/tests/chromium/chromium.spec.ts b/examples/playwright-voiceover/tests/chromium/chromium.spec.ts index aceb4d7..73a7897 100644 --- a/examples/playwright-voiceover/tests/chromium/chromium.spec.ts +++ b/examples/playwright-voiceover/tests/chromium/chromium.spec.ts @@ -6,6 +6,8 @@ import { macOSRecord } from "@guidepup/guidepup"; import spokenPhraseSnapshot from "./chromium.spokenPhrase.snapshot.json"; import { voiceOverTest as test } from "../../../../src"; +test.use({ voiceOverStartOptions: { capture: "initial" } }); + test.describe("Chromium Playwright VoiceOver", () => { test("I can navigate the Guidepup Github page", async ({ browser, diff --git a/examples/playwright-voiceover/tests/firefox/firefox.spec.ts b/examples/playwright-voiceover/tests/firefox/firefox.spec.ts index 9afddc3..4b2a04e 100644 --- a/examples/playwright-voiceover/tests/firefox/firefox.spec.ts +++ b/examples/playwright-voiceover/tests/firefox/firefox.spec.ts @@ -6,6 +6,8 @@ import { macOSRecord } from "@guidepup/guidepup"; import spokenPhraseSnapshot from "./firefox.spokenPhrase.snapshot.json"; import { voiceOverTest as test } from "../../../../src"; +test.use({ voiceOverStartOptions: { capture: "initial" } }); + test.describe("Firefox Playwright VoiceOver", () => { test("I can navigate the Guidepup Github page", async ({ browser, diff --git a/examples/playwright-voiceover/tests/webkit/webkit.spec.ts b/examples/playwright-voiceover/tests/webkit/webkit.spec.ts index 1d848df..a36d8aa 100644 --- a/examples/playwright-voiceover/tests/webkit/webkit.spec.ts +++ b/examples/playwright-voiceover/tests/webkit/webkit.spec.ts @@ -6,6 +6,8 @@ import { macOSRecord } from "@guidepup/guidepup"; import spokenPhraseSnapshot from "./webkit.spokenPhrase.snapshot.json"; import { voiceOverTest as test } from "../../../../src"; +test.use({ voiceOverStartOptions: { capture: "initial" } }); + test.describe("Webkit Playwright VoiceOver", () => { test("I can navigate the Guidepup Github page", async ({ browser, diff --git a/src/nvdaTest.ts b/src/nvdaTest.ts index 08dcaa6..9dd193c 100644 --- a/src/nvdaTest.ts +++ b/src/nvdaTest.ts @@ -1,8 +1,15 @@ import { test } from "@playwright/test"; import { nvda, WindowsKeyCodes, WindowsModifiers } from "@guidepup/guidepup"; -import type { NVDA } from "@guidepup/guidepup"; +import type { CommandOptions, NVDA } from "@guidepup/guidepup"; import { applicationNameMap } from "./applicationNameMap"; +type Prettify = { + [K in keyof T]: T[K]; + // eslint-disable-next-line @typescript-eslint/ban-types +} & {}; + +type CaptureCommandOptions = Prettify>; + /** * [API Reference](https://www.guidepup.dev/docs/api/class-nvda) * @@ -108,8 +115,14 @@ export const nvdaTest = test.extend<{ * ``` */ nvda: NVDAPlaywright; + /** + * [API Reference](https://www.guidepup.dev/docs/api/class-command-options) + * + * Options to start NVDA with, see also [nvda.start([options])](https://www.guidepup.dev/docs/api/class-nvda#nvda-start). + */ + nvdaStartOptions: CaptureCommandOptions; }>({ - nvda: async ({ browserName, page }, use) => { + nvda: async ({ browserName, page, nvdaStartOptions }, use) => { try { const applicationName = applicationNameMap[browserName]; @@ -158,7 +171,7 @@ export const nvdaTest = test.extend<{ await nvdaPlaywright.clearSpokenPhraseLog(); }; - await nvdaPlaywright.start(); + await nvdaPlaywright.start(nvdaStartOptions); await use(nvdaPlaywright); } finally { diff --git a/src/voiceOverTest.ts b/src/voiceOverTest.ts index 8fe4048..d9033f0 100644 --- a/src/voiceOverTest.ts +++ b/src/voiceOverTest.ts @@ -1,6 +1,6 @@ import { test } from "@playwright/test"; import { voiceOver, macOSActivate } from "@guidepup/guidepup"; -import type { VoiceOver } from "@guidepup/guidepup"; +import type { CommandOptions, VoiceOver } from "@guidepup/guidepup"; import { applicationNameMap } from "./applicationNameMap"; /** @@ -74,8 +74,15 @@ export const voiceOverTest = test.extend<{ * ``` */ voiceOver: VoiceOverPlaywright; + /** + * [API Reference](https://www.guidepup.dev/docs/api/class-command-options) + * + * Options to start VoiceOver with, see also [voiceOver.start([options])](https://www.guidepup.dev/docs/api/class-voiceover#voiceover-start). + */ + voiceOverStartOptions: CommandOptions; }>({ - voiceOver: async ({ browserName, page }, use) => { + voiceOverStartOptions: {}, + voiceOver: async ({ browserName, page, voiceOverStartOptions }, use) => { try { const applicationName = applicationNameMap[browserName]; @@ -103,7 +110,7 @@ export const voiceOverTest = test.extend<{ await voiceOverPlaywright.clearSpokenPhraseLog(); }; - await voiceOverPlaywright.start(); + await voiceOverPlaywright.start(voiceOverStartOptions); await macOSActivate(applicationName); await use(voiceOverPlaywright); } finally { From 4a072b66be791d7b0770ca5d3f59d03b384d74b9 Mon Sep 17 00:00:00 2001 From: jlp-craigmorten Date: Thu, 25 Jul 2024 16:13:46 +0100 Subject: [PATCH 2/2] fix: missing config --- src/nvdaTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nvdaTest.ts b/src/nvdaTest.ts index 9dd193c..8d599cb 100644 --- a/src/nvdaTest.ts +++ b/src/nvdaTest.ts @@ -122,6 +122,7 @@ export const nvdaTest = test.extend<{ */ nvdaStartOptions: CaptureCommandOptions; }>({ + nvdaStartOptions: {}, nvda: async ({ browserName, page, nvdaStartOptions }, use) => { try { const applicationName = applicationNameMap[browserName];