Skip to content

Commit

Permalink
test: guidepup
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerget committed Jul 22, 2024
1 parent a006128 commit b324552
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
22 changes: 7 additions & 15 deletions showcases/screen-reader/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ const cleanSpeakInstructions = (phraseLog: string[]): string[] =>

export const generateSnapshot = async (
screenReader?: VoiceOverPlaywright | NVDAPlaywright,
shiftFirst?: boolean,
retry?: number
) => {
if (!screenReader) return;

let phraseLog: string[] = await screenReader.spokenPhraseLog();
if (shiftFirst) {
phraseLog.shift();
}

if (retry && retry > 0) {
process.stdout.write(JSON.stringify(phraseLog));
Expand Down Expand Up @@ -100,19 +96,15 @@ export const runTest = async ({
nvda ?? voiceOver;
if (!screenRecorder) return;

/**
* In macOS:Webkit the [automaticallySpeakWebPage](https://github.com/guidepup/guidepup/blob/main/src/macOS/VoiceOver/configureSettings.ts#L58) is acitve.
* Therefore, we need to move back with the cursor to the start and delete the logs before starting.
* In windows:Chrome the cursor is on the middle element.
* Therefore, we need to move back and delete the logs, and then start everything.
*/
await screenRecorder.navigateToWebContent();
await page.waitForTimeout(500);

if (voiceOver) {
await voiceOver.perform('read contents of voiceover cursor' as any);
const lastPhrase = await voiceOver.lastSpokenPhrase();
await voiceOver.clearSpokenPhraseLog();
if (lastPhrase.includes('You are currently')) {
// We stop interacting here because screenRecorder.navigateToWebContent() calls voiceOver.interact()
await voiceOver.stopInteracting();
}
}

await testFn?.(voiceOver, nvda);
await postTestFn?.(voiceOver, nvda, retry);
recorder?.();
Expand All @@ -121,7 +113,7 @@ export const runTest = async ({
export const testDefault = (defaultTestType: DefaultTestType) => {
const { test, title, additionalParams, postTestFn } = defaultTestType;
const fallbackPostFn = async (voiceOver, nvda, retry) => {
await generateSnapshot(voiceOver ?? nvda, nvda, retry);
await generateSnapshot(voiceOver ?? nvda, retry);
};

const testType: DefaultTestType = {
Expand Down
22 changes: 14 additions & 8 deletions showcases/screen-reader/tests/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ test.describe('DBButton', () => {
title: 'should not have icon in screen reader (next)',
url: './#/02/button?page=content',
async testFn(voiceOver, nvda) {
const screenReader = voiceOver ?? nvda;
if (nvda) {
await screenReader?.next();
await screenReader?.previous();
await nvda?.next();
} else if (voiceOver) {
await voiceOver?.previous();
}

const screenReader = voiceOver ?? nvda;
await screenReader?.clearSpokenPhraseLog();
await screenReader?.previous();
await screenReader?.next();
await screenReader?.next();
}
Expand All @@ -23,14 +26,17 @@ test.describe('DBButton', () => {
title: 'should not have icon in screen reader (tab)',
url: './#/02/button?page=content',
async testFn(voiceOver, nvda) {
const screenReader = voiceOver ?? nvda;
if (nvda) {
await screenReader?.press('Tab');
await screenReader?.press('Shift+Tab');
await nvda?.press('Tab');
} else if (voiceOver) {
await voiceOver?.press('Shift+Tab');
}

await screenReader?.press('Tab');
await screenReader?.press('Tab');
const screenReader = voiceOver ?? nvda;
await screenReader?.clearSpokenPhraseLog();
await nvda?.press('Shift+Tab');
await nvda?.press('Tab');
await nvda?.press('Tab');
}
});
});
9 changes: 5 additions & 4 deletions showcases/screen-reader/tests/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ test.describe('DBInput', () => {
title: 'should have message and label (tab)',
url: './#/03/input?page=variant%20helper%20message',
async testFn(voiceOver, nvda) {
const screenReader = voiceOver ?? nvda;
if (nvda) {
await screenReader?.press('Tab');
await screenReader?.press('Shift+Tab');
await nvda?.press('Tab');
}

await screenReader?.press('Tab');
const screenReader = voiceOver ?? nvda;
await screenReader?.clearSpokenPhraseLog();
await nvda?.press('Shift+Tab');
await nvda?.press('Tab');
}
});
});
16 changes: 10 additions & 6 deletions showcases/screen-reader/tests/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ test.describe('DBRadio', () => {
title: 'should label duplicated (next)',
url: './#/03/radio?page=density',
async testFn(voiceOver, nvda) {
const screenReader = voiceOver ?? nvda;
if (nvda) {
await screenReader?.next();
await screenReader?.previous();
await nvda?.next();
} else if (voiceOver) {
await voiceOver?.previous();
}

const screenReader = voiceOver ?? nvda;
await screenReader?.clearSpokenPhraseLog();
await screenReader?.previous();
await screenReader?.next();
await screenReader?.next();
}
Expand All @@ -22,12 +25,13 @@ test.describe('DBRadio', () => {
title: 'should label duplicated (arrows)',
url: './#/03/radio?page=density',
async testFn(voiceOver, nvda) {
const screenReader = voiceOver ?? nvda;
if (nvda) {
await screenReader?.press('Left');
await screenReader?.press('Left');
await nvda?.press('Left');
}

const screenReader = voiceOver ?? nvda;
await screenReader?.clearSpokenPhraseLog();
await screenReader?.press('Left');
await screenReader?.press('Right');
await screenReader?.press('Right');
}
Expand Down

0 comments on commit b324552

Please sign in to comment.