Skip to content

Commit 0edd62a

Browse files
authored
[#5] Correct application names for non-webkit browsers (#6)
* feat: fill out remaining browser mappings
1 parent 5a9d915 commit 0edd62a

File tree

9 files changed

+87
-46
lines changed

9 files changed

+87
-46
lines changed

example/playwright.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const config: PlaywrightTestConfig = {
1212
name: "webkit",
1313
use: { ...devices["Desktop Safari"], headless: false, video: "on" },
1414
},
15+
{
16+
name: "chromium",
17+
use: { ...devices["Desktop Chrome"], headless: false, video: "on" },
18+
},
1519
],
1620
};
1721

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
"heading level 1 guidepup/guidepup",
3+
"heading level 2 Latest commit",
4+
"heading level 2 Git stats",
5+
"heading level 2 Files",
6+
"heading level 2 link README.md",
7+
"heading level 1 Guidepup"
8+
]

example/tests/chromium.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect } from "@playwright/test";
2+
import snapshot from "./chromium.snapshot.json";
3+
import { voTest as test } from "../../src";
4+
5+
test.describe("Chromium VoiceOver", () => {
6+
test("I can navigate the Guidepup Github page", async ({
7+
browserName,
8+
page,
9+
voiceOver,
10+
}) => {
11+
test.skip(browserName !== "chromium", "Chromium only test");
12+
13+
// Navigate to Guidepup GitHub page 🎉
14+
await page.goto("https://github.com/guidepup/guidepup", {
15+
waitUntil: "domcontentloaded",
16+
});
17+
18+
// Wait for page to be ready and interact 🙌
19+
await expect(page.locator('header[role="banner"]')).toBeVisible();
20+
await voiceOver.stopInteracting();
21+
await voiceOver.interact();
22+
23+
// Move across the page menu to the Guidepup heading using VoiceOver 🔎
24+
while ((await voiceOver.itemText()) !== "Guidepup heading level 1") {
25+
await voiceOver.perform(voiceOver.keyboard.commands.findNextHeading);
26+
}
27+
28+
// Assert that we've ended up where we expected and what we were told on
29+
// the way there is as expected.
30+
const spokenPhraseLog = await voiceOver.spokenPhraseLog();
31+
32+
for (const expectedPhrase of snapshot) {
33+
expect(
34+
!!spokenPhraseLog.find((log) => log.includes(expectedPhrase))
35+
).toBe(true);
36+
}
37+
});
38+
});

example/tests/itemTextSnapshot.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

example/tests/webkit.snapshot.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
"heading level 1 guidepup/guidepup",
3+
"heading level 2 Latest commit",
4+
"heading level 2 Git stats",
5+
"heading level 2 Files",
6+
"heading level 2 link README.md",
7+
"heading level 1 Guidepup"
8+
]
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
11
import { expect } from "@playwright/test";
2-
import itemTextSnapshot from "./itemTextSnapshot.json";
2+
import snapshot from "./webkit.snapshot.json";
33
import { voTest as test } from "../../src";
44

5-
function delay(ms: number) {
6-
return new Promise((resolve) => setTimeout(resolve, ms));
7-
}
8-
9-
async function waitForWebContentAnnouncement(voiceOver) {
10-
for (let i = 0; i < 10; i++) {
11-
const itemText = await voiceOver.itemText();
12-
13-
if (itemText?.includes("web content")) {
14-
return;
15-
}
16-
17-
await delay(50);
18-
}
19-
20-
throw new Error("web content could not be found");
21-
}
22-
235
test.describe("Playwright VoiceOver", () => {
246
test("I can navigate the Guidepup Github page", async ({
7+
browserName,
258
page,
269
voiceOver,
2710
}) => {
11+
test.skip(browserName !== "webkit", "Webkit only test");
12+
2813
// Navigate to Guidepup GitHub page 🎉
2914
await page.goto("https://github.com/guidepup/guidepup", {
3015
waitUntil: "domcontentloaded",
3116
});
3217

3318
// Wait for page to be ready and interact 🙌
3419
await expect(page.locator('header[role="banner"]')).toBeVisible();
35-
await waitForWebContentAnnouncement(voiceOver);
3620
await voiceOver.interact();
3721

3822
// Move across the page menu to the Guidepup heading using VoiceOver 🔎
@@ -42,10 +26,10 @@ test.describe("Playwright VoiceOver", () => {
4226

4327
// Assert that we've ended up where we expected and what we were told on
4428
// the way there is as expected.
45-
const itemTextLog = await voiceOver.itemTextLog();
29+
const spokenPhraseLog = await voiceOver.spokenPhraseLog();
4630

47-
for (const expectedItem of itemTextSnapshot) {
48-
expect(itemTextLog).toContain(expectedItem);
31+
for (const expectedPhrase of snapshot) {
32+
expect(!!spokenPhraseLog.find(log => log.includes(expectedPhrase))).toBe(true);
4933
}
5034
});
5135
});

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@guidepup/playwright",
3-
"version": "0.7.5",
4-
"description": "Screen-reader driver for Playwright.",
3+
"version": "0.8.0",
4+
"description": "Screen reader driver for Playwright tests.",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
77
"author": "Craig Morten <[email protected]>",
@@ -29,11 +29,11 @@
2929
"lint": "eslint . --ext .ts",
3030
"lint:fix": "yarn lint --fix",
3131
"prepublish": "yarn build",
32-
"pretest": "npx playwright install webkit",
33-
"test": "playwright test -c ./example/playwright.config.ts ./example/tests/playwright.spec.ts"
32+
"pretest": "npx playwright install webkit chromium",
33+
"test": "playwright test -c ./example/playwright.config.ts ./example/tests/"
3434
},
3535
"dependencies": {
36-
"@guidepup/guidepup": "^0.14.7"
36+
"@guidepup/guidepup": "^0.15.0"
3737
},
3838
"devDependencies": {
3939
"@playwright/test": "^1.28.1",

src/voTest.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
/* eslint-disable no-empty-pattern */
21
import { test } from "@playwright/test";
32
import { voiceOver, macOSActivate } from "@guidepup/guidepup";
43

5-
const PLAYWRIGHT_APPLICATION = "Playwright";
4+
const applicationNameMap = {
5+
chromium: "Chromium",
6+
chrome: "Google Chrome",
7+
"chrome-beta": "Google Chrome Beta",
8+
msedge: "Microsoft Edge",
9+
"msedge-beta": "Microsoft Edge Beta",
10+
"msedge-dev": "Microsoft Edge Dev",
11+
firefox: "Nightly",
12+
webkit: "Playwright",
13+
};
614

715
/**
816
* These tests extend the default Playwright environment that launches the
9-
* browser with a running instance of the VoiceOver screen-reader for MacOS.
17+
* browser with a running instance of the VoiceOver screen reader for MacOS.
1018
*
1119
* A fresh started VoiceOver instance `vo` is provided to each test.
1220
*/
1321
const voTest = test.extend<{ voiceOver: typeof voiceOver }>({
14-
voiceOver: async ({}, use) => {
22+
voiceOver: async ({ browserName }, use) => {
1523
try {
1624
await voiceOver.start();
17-
await macOSActivate(PLAYWRIGHT_APPLICATION);
25+
await macOSActivate(applicationNameMap[browserName]);
1826
await use(voiceOver);
1927
} finally {
2028
await voiceOver.stop();

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
minimatch "^3.0.4"
3030
strip-json-comments "^3.1.1"
3131

32-
"@guidepup/guidepup@^0.14.7":
33-
version "0.14.7"
34-
resolved "https://registry.yarnpkg.com/@guidepup/guidepup/-/guidepup-0.14.7.tgz#d83ba5295126b2f391de7c10d0554d5d09b82614"
35-
integrity sha512-q/uSktR+eumcgqTmo7ZqW2EMhw3o/ki1btxHWqGxBWJgoQHPz6+zWqzv15VgcmSipG8EOCpcfbWOnEOE00o53A==
32+
"@guidepup/guidepup@^0.15.0":
33+
version "0.15.0"
34+
resolved "https://registry.yarnpkg.com/@guidepup/guidepup/-/guidepup-0.15.0.tgz#d9cd40f933f31c03d65f6bef9a31fee953654cc0"
35+
integrity sha512-MUPtcp57e6Ehtgtn29nb1spObIz4dUA3aTj+FL4RGBGmv2q+YPXJ0zEKP2MP04QsTAJ5fL8vN2nddmnGGxSS+w==
3636

3737
"@humanwhocodes/config-array@^0.9.2":
3838
version "0.9.2"

0 commit comments

Comments
 (0)