Skip to content

Commit

Permalink
feat: upgrade @guidepup/playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorten committed Jan 20, 2024
1 parent fbc30c2 commit 9044840
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 220 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
"test:report": "ts-node src/report.ts"
},
"dependencies": {
"@guidepup/guidepup": "^0.21.1",
"@guidepup/playwright": "^0.12.0",
"@playwright/test": "^1.40.1",
"@guidepup/guidepup": "^0.22.0",
"@guidepup/playwright": "^0.13.1",
"@playwright/test": "^1.41.1",
"csvtojson": "^2.0.10",
"playwright-merge-html-reports": "^0.2.8"
},
"devDependencies": {
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"ts-node": "^10.9.2",
Expand Down
28 changes: 14 additions & 14 deletions src/macOsVoiceOver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { platform, release } from "os";
import { voTest as test } from "@guidepup/playwright";
import { VoiceOver } from "@guidepup/guidepup";
import { KeyCodes } from "@guidepup/guidepup/lib/macOS/KeyCodes";
import { Modifiers } from "@guidepup/guidepup/lib/macOS/Modifiers";
import { voiceOverTest as test } from "@guidepup/playwright";
import { VoiceOver, MacOSKeyCodes, MacOSModifiers } from "@guidepup/guidepup";
import { record } from "./record";
import { setup } from "./setup";
import { readTestSuitesCacheSync, TestSuite } from "./testSuites";
Expand All @@ -28,7 +26,7 @@ const mapCommand = (
| {
error?: undefined;
voiceOverCommand: true;
mappedCommand: { keyCode: KeyCodes[]; modifiers: Modifiers[] };
mappedCommand: { keyCode: MacOSKeyCodes[]; modifiers: MacOSModifiers[] };
}
| {
error?: undefined;
Expand All @@ -41,14 +39,14 @@ const mapCommand = (
keys.includes("Control") && keys.includes("Options");

if (isVoiceOverCommand) {
const keyCodes: KeyCodes[] = [];
const modifiers: Modifiers[] = [];
const keyCodes: MacOSKeyCodes[] = [];
const modifiers: MacOSModifiers[] = [];

for (const key of keys) {
if (typeof Modifiers[key] !== "undefined") {
modifiers.push(Modifiers[key]);
} else if (typeof KeyCodes[key] !== "undefined") {
keyCodes.push(KeyCodes[key as keyof KeyCodes]);
if (typeof MacOSModifiers[key] !== "undefined") {
modifiers.push(MacOSModifiers[key]);
} else if (typeof MacOSKeyCodes[key] !== "undefined") {
keyCodes.push(MacOSKeyCodes[key as keyof MacOSKeyCodes]);
} else {
return { error: true };
}
Expand All @@ -67,9 +65,9 @@ const mapCommand = (
const modifiers: string[] = [];

for (const key of keys) {
if (typeof Modifiers[key] !== "undefined") {
if (typeof MacOSModifiers[key] !== "undefined") {
modifiers.push(key);
} else if (typeof KeyCodes[key] !== "undefined") {
} else if (typeof MacOSKeyCodes[key] !== "undefined") {
keyCodes.push(key);
} else {
return { error: true };
Expand Down Expand Up @@ -169,11 +167,13 @@ const generateTestSuite = ({
test.describe(screenReaderTest.title, () => {
let stopRecording: () => string;

test.beforeEach(async ({ page, voiceOver }) => {
test.beforeEach(async ({ browser, browserName, page, voiceOver }) => {
table(screenReaderTest);

try {
stopRecording = record({
browserName,
browserVersion: browser.version(),
test,
screenReaderName,
});
Expand Down
100 changes: 0 additions & 100 deletions src/nvdaTest.ts

This file was deleted.

8 changes: 6 additions & 2 deletions src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { join } from "path";
import { table } from "./log";

export function record({
browserName,
browserVersion,
screenReaderName,
test,
}: {
browserName: string;
browserVersion: string;
screenReaderName: string;
test: typeof playwrightTest;
}): () => string {
Expand All @@ -22,7 +26,7 @@ export function record({

switch (platformName) {
case "darwin": {
const recordingFileName = `test_${platformName}_${release()}_${screenReaderName}_${sanitizedTitle}_attempt_${retry}.mov`;
const recordingFileName = `test_${platformName}_${release()}_${browserName}_${browserVersion}_${screenReaderName}_${sanitizedTitle}_attempt_${retry}.mov`;
const recordingFilePath = join("./recordings/", recordingFileName);

table({ recordingFileName });
Expand All @@ -36,7 +40,7 @@ export function record({
};
}
case "win32": {
const recordingFileName = `test_${platformName}_${release()}_${screenReaderName}_${sanitizedTitle}_attempt_${retry}.mp4`;
const recordingFileName = `test_${platformName}_${release()}_${browserName}_${browserVersion}_${screenReaderName}_${sanitizedTitle}_attempt_${retry}.mp4`;
const recordingFilePath = join("./recordings/", recordingFileName);

table({ recordingFileName });
Expand Down
17 changes: 7 additions & 10 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Page } from "@playwright/test";
import { delay } from "./delay";
import { ScreenReader } from "@guidepup/guidepup";
import { Test } from "./types";
import { log } from "./log";
import { VoiceOverPlaywright, NVDAPlaywright } from "@guidepup/playwright";

const PAGE_LOAD_DELAY = 500;

export async function setup({
hasSetupScript,
mode,
moveToSystemFocusCommand,
page,
screenReader,
setMode,
Expand All @@ -19,13 +18,13 @@ export async function setup({
mode: Test["mode"];
moveToSystemFocusCommand: unknown;
page: Page;
screenReader: ScreenReader;
screenReader: VoiceOverPlaywright | NVDAPlaywright;
setMode: ({
mode,
screenReader,
}: {
mode: Test["mode"];
screenReader: ScreenReader;
screenReader: VoiceOverPlaywright | NVDAPlaywright;
}) => void | Promise<void>;
testUrl: string;
}): Promise<void> {
Expand All @@ -34,14 +33,12 @@ export async function setup({
await page.goto(testUrl, { waitUntil: "load" });
await delay(PAGE_LOAD_DELAY);

await screenReader.perform(moveToSystemFocusCommand);
await screenReader.perform(moveToSystemFocusCommand);
await screenReader.perform(moveToSystemFocusCommand);

await screenReader.clearSpokenPhraseLog();
await screenReader.clearItemTextLog();
await screenReader.navigateToWebContent();

if (hasSetupScript) {
await page.goto(testUrl, { waitUntil: "load" });
await delay(PAGE_LOAD_DELAY);

log("Running test setup.");

await screenReader.act();
Expand Down
24 changes: 12 additions & 12 deletions src/windowsNvda.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { platform, release } from "os";
import { nvdaTest as test } from "./nvdaTest";
import { NVDA } from "@guidepup/guidepup";
import { KeyCodes } from "@guidepup/guidepup/lib/windows/KeyCodes";
import { Modifiers } from "@guidepup/guidepup/lib/windows/Modifiers";
import { NVDAPlaywright, nvdaTest as test } from "@guidepup/playwright";
import { NVDA, WindowsKeyCodes, WindowsModifiers } from "@guidepup/guidepup";
import { record } from "./record";
import { setup } from "./setup";
import { readTestSuitesCacheSync, TestSuite } from "./testSuites";
Expand All @@ -21,15 +19,15 @@ test.describe.configure({ mode: "parallel" });

const screenReaderName = "nvda";

type KeyCodesType = (typeof KeyCodes)[keyof typeof KeyCodes];
type ModifiersType = (typeof Modifiers)[keyof typeof Modifiers];
type KeyCodesType = (typeof WindowsKeyCodes)[keyof typeof WindowsKeyCodes];
type ModifiersType = (typeof WindowsModifiers)[keyof typeof WindowsModifiers];

const setMode = async ({
mode,
screenReader,
}: {
mode: Test["mode"];
screenReader: NVDA;
screenReader: NVDAPlaywright;
}) => {
if (mode === "interaction") {
await screenReader.perform(screenReader.keyboardCommands.exitFocusMode);
Expand All @@ -55,10 +53,10 @@ const mapCommand = (
const modifiers: ModifiersType[] = [];

for (const key of keys) {
if (typeof Modifiers[key] !== "undefined") {
modifiers.push(Modifiers[key]);
} else if (typeof KeyCodes[key] !== "undefined") {
keyCodes.push(KeyCodes[key]);
if (typeof WindowsModifiers[key] !== "undefined") {
modifiers.push(WindowsModifiers[key]);
} else if (typeof WindowsKeyCodes[key] !== "undefined") {
keyCodes.push(WindowsKeyCodes[key]);
} else {
return { error: true };
}
Expand Down Expand Up @@ -141,11 +139,13 @@ const generateTestSuite = ({
test.describe(screenReaderTest.title, () => {
let stopRecording: () => string;

test.beforeEach(async ({ page, nvda }) => {
test.beforeEach(async ({ browser, browserName, page, nvda }) => {
table(screenReaderTest);

try {
stopRecording = record({
browserName,
browserVersion: browser.version(),
test,
screenReaderName,
});
Expand Down
Loading

0 comments on commit 9044840

Please sign in to comment.