Skip to content
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

feat: allow setting of start options #17

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading