@guidepup/playwright 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -3
- package/lib/nvdaTest.js +21 -32
- package/lib/voiceOverTest.js +0 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,9 +71,51 @@ const config: PlaywrightTestConfig = {
|
|
|
71
71
|
export default config;
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
Check out the configuration this adds [in the `config.ts
|
|
74
|
+
Check out the configuration this adds [in the `config.ts` file](./src/config.ts).
|
|
75
75
|
|
|
76
|
-
###
|
|
76
|
+
### Web Content Navigation
|
|
77
|
+
|
|
78
|
+
In addition to the Guidepup APIs the `voiceOver` and `nvda` instances provided by the Guidepup Playwright setup have an additional utility method `.navigateToWebContent()`.
|
|
79
|
+
|
|
80
|
+
This method will navigate the screen reader to the first element of the document body in the browser.
|
|
81
|
+
|
|
82
|
+
Use this method after you navigate to a page and have made any necessary checks that the page has loaded as expected. For example, this is how you might use the method with NVDA:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// Navigate to the desired page
|
|
86
|
+
await page.goto("https://github.com/guidepup/guidepup", {
|
|
87
|
+
waitUntil: "load",
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Wait for page to be ready
|
|
91
|
+
await page.locator('header[role="banner"]').waitFor();
|
|
92
|
+
|
|
93
|
+
// Navigate to the web content
|
|
94
|
+
await nvda.navigateToWebContent();
|
|
95
|
+
|
|
96
|
+
// ... some commands
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Note:** This command clears all logs meaning `.spokenPhraseLog()` and `.itemTextLog()` are emptied. If logs from prior to the command are required, first store the logs in a variable for later use:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
// ... some commands
|
|
103
|
+
|
|
104
|
+
// Store spoken phrases
|
|
105
|
+
const spokenPhrases = await nvda.spokenPhraseLog();
|
|
106
|
+
|
|
107
|
+
// Navigate to the web content
|
|
108
|
+
await nvda.navigateToWebContent();
|
|
109
|
+
|
|
110
|
+
// ... some commands
|
|
111
|
+
|
|
112
|
+
// Collect all spoken phrasees
|
|
113
|
+
const allSpokenPhrases = [...spokenPhrases, ...(await nvda.spokenPhraseLog())];
|
|
114
|
+
|
|
115
|
+
// ... do something with spoken phrases
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### VoiceOver Example
|
|
77
119
|
|
|
78
120
|
`playwright.config.ts`:
|
|
79
121
|
|
|
@@ -131,7 +173,7 @@ test.describe("Playwright VoiceOver", () => {
|
|
|
131
173
|
});
|
|
132
174
|
```
|
|
133
175
|
|
|
134
|
-
### NVDA
|
|
176
|
+
### NVDA Example
|
|
135
177
|
|
|
136
178
|
`playwright.config.ts`:
|
|
137
179
|
|
package/lib/nvdaTest.js
CHANGED
|
@@ -10,41 +10,23 @@ const SWITCH_APPLICATION = {
|
|
|
10
10
|
keyCode: [guidepup_1.WindowsKeyCodes.Escape],
|
|
11
11
|
modifiers: [guidepup_1.WindowsModifiers.Alt],
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const MOVE_TO_TOP = {
|
|
14
|
+
keyCode: [guidepup_1.WindowsKeyCodes.Home],
|
|
15
|
+
modifiers: [guidepup_1.WindowsModifiers.Control],
|
|
16
|
+
};
|
|
17
|
+
const focusBrowser = async ({ applicationName, }) => {
|
|
14
18
|
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.reportTitle);
|
|
15
19
|
let windowTitle = await nvdaPlaywright.lastSpokenPhrase();
|
|
16
20
|
if (windowTitle.includes(applicationName)) {
|
|
17
21
|
return;
|
|
18
22
|
}
|
|
19
|
-
// Firefox has a bug with NVDA where NVDA gets stuck in focus mode if
|
|
20
|
-
// Firefox is the currently focused application.
|
|
21
|
-
// REF: https://github.com/nvaccess/nvda/issues/5758
|
|
22
|
-
// We swap to a different application, restart NVDA, and then switch back.
|
|
23
23
|
let applicationSwitchRetryCount = 0;
|
|
24
24
|
while (applicationSwitchRetryCount < MAX_APPLICATION_SWITCH_RETRY_COUNT) {
|
|
25
25
|
applicationSwitchRetryCount++;
|
|
26
26
|
await nvdaPlaywright.perform(SWITCH_APPLICATION);
|
|
27
27
|
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.reportTitle);
|
|
28
28
|
windowTitle = await nvdaPlaywright.lastSpokenPhrase();
|
|
29
|
-
if (
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
await nvdaPlaywright.stop();
|
|
34
|
-
await nvdaPlaywright.start();
|
|
35
|
-
await page.bringToFront();
|
|
36
|
-
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.reportTitle);
|
|
37
|
-
windowTitle = await nvdaPlaywright.lastSpokenPhrase();
|
|
38
|
-
if (windowTitle.includes(applicationName)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
applicationSwitchRetryCount = 0;
|
|
42
|
-
while (applicationSwitchRetryCount < MAX_APPLICATION_SWITCH_RETRY_COUNT) {
|
|
43
|
-
applicationSwitchRetryCount++;
|
|
44
|
-
await nvdaPlaywright.perform(SWITCH_APPLICATION);
|
|
45
|
-
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.reportTitle);
|
|
46
|
-
windowTitle = await nvdaPlaywright.lastSpokenPhrase();
|
|
47
|
-
if (!windowTitle.includes(applicationName)) {
|
|
29
|
+
if (windowTitle.includes(applicationName)) {
|
|
48
30
|
break;
|
|
49
31
|
}
|
|
50
32
|
}
|
|
@@ -67,16 +49,23 @@ exports.nvdaTest = test_1.test.extend({
|
|
|
67
49
|
nvdaPlaywright.navigateToWebContent = async () => {
|
|
68
50
|
// Make sure NVDA is not in focus mode.
|
|
69
51
|
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.exitFocusMode);
|
|
70
|
-
await nvdaPlaywright.lastSpokenPhrase();
|
|
71
52
|
// Ensure application is brought to front and focused.
|
|
72
|
-
await focusBrowser({ applicationName
|
|
73
|
-
//
|
|
53
|
+
await focusBrowser({ applicationName });
|
|
54
|
+
// NVDA appears to not work well with Firefox when switching between
|
|
55
|
+
// applications resulting in the entire browser window having NVDA focus
|
|
56
|
+
// with focus mode.
|
|
57
|
+
//
|
|
58
|
+
// One workaround is to tab to the next focusable item. From there we can
|
|
59
|
+
// toggle into (yes although we are already in it...) focus mode and back
|
|
60
|
+
// out. In case this ever transpires to not happen as expect, we then ensure
|
|
61
|
+
// we exit focus mode and move NVDA to the top of the page.
|
|
62
|
+
//
|
|
63
|
+
// REF: https://github.com/nvaccess/nvda/issues/5758
|
|
64
|
+
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.readNextFocusableItem);
|
|
65
|
+
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.toggleBetweenBrowseAndFocusMode);
|
|
66
|
+
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.toggleBetweenBrowseAndFocusMode);
|
|
74
67
|
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.exitFocusMode);
|
|
75
|
-
await nvdaPlaywright.
|
|
76
|
-
// Ensure the document is ready and focused.
|
|
77
|
-
await page.bringToFront();
|
|
78
|
-
await page.locator("body").waitFor();
|
|
79
|
-
await page.locator("body").focus();
|
|
68
|
+
await nvdaPlaywright.perform(MOVE_TO_TOP);
|
|
80
69
|
// Clear out logs.
|
|
81
70
|
await nvdaPlaywright.clearItemTextLog();
|
|
82
71
|
await nvdaPlaywright.clearSpokenPhraseLog();
|
package/lib/voiceOverTest.js
CHANGED
|
@@ -27,9 +27,7 @@ exports.voiceOverTest = test_1.test.extend({
|
|
|
27
27
|
await page.locator("body").focus();
|
|
28
28
|
// Navigate to the beginning of the web content.
|
|
29
29
|
await voiceOverPlaywright.interact();
|
|
30
|
-
await voiceOverPlaywright.lastSpokenPhrase();
|
|
31
30
|
await voiceOverPlaywright.perform(voiceOverPlaywright.keyboardCommands.jumpToLeftEdge);
|
|
32
|
-
await voiceOverPlaywright.lastSpokenPhrase();
|
|
33
31
|
// Clear out logs.
|
|
34
32
|
await voiceOverPlaywright.clearItemTextLog();
|
|
35
33
|
await voiceOverPlaywright.clearSpokenPhraseLog();
|