Skip to content

Commit

Permalink
feat: allow setting of start options (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlp-craigmorten authored Jul 25, 2024
1 parent 7632467 commit 7ddd0d2
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ dist
lib
.DS_Store
test-results
recordings
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
2 changes: 2 additions & 0 deletions examples/playwright-nvda/tests/chromium/chromium.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions examples/playwright-nvda/tests/firefox/firefox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions examples/playwright-voiceover/tests/chromium/chromium.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions examples/playwright-voiceover/tests/firefox/firefox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions examples/playwright-voiceover/tests/webkit/webkit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 17 additions & 3 deletions src/nvdaTest.ts
Original file line number Diff line number Diff line change
@@ -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<T> = {
[K in keyof T]: T[K];
// eslint-disable-next-line @typescript-eslint/ban-types
} & {};

type CaptureCommandOptions = Prettify<Pick<CommandOptions, "capture">>;

/**
* [API Reference](https://www.guidepup.dev/docs/api/class-nvda)
*
Expand Down Expand Up @@ -108,8 +115,15 @@ 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) => {
nvdaStartOptions: {},
nvda: async ({ browserName, page, nvdaStartOptions }, use) => {
try {
const applicationName = applicationNameMap[browserName];

Expand Down Expand Up @@ -158,7 +172,7 @@ export const nvdaTest = test.extend<{
await nvdaPlaywright.clearSpokenPhraseLog();
};

await nvdaPlaywright.start();
await nvdaPlaywright.start(nvdaStartOptions);

await use(nvdaPlaywright);
} finally {
Expand Down
13 changes: 10 additions & 3 deletions src/voiceOverTest.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7ddd0d2

Please sign in to comment.