Skip to content
Open
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
18 changes: 15 additions & 3 deletions src/nvdaTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,26 @@ const MOVE_TO_TOP = {
modifiers: [WindowsModifiers.Control],
};

type FocusBrowserParams = {
applicationName: string;
pageTitle: string;
}

const hasFocus = ({applicationName, pageTitle, windowTitle}:FocusBrowserParams & {windowTitle:string})=>{
return (pageTitle.length && windowTitle.startsWith(pageTitle)) || windowTitle.includes(applicationName)
}

const focusBrowser = async ({
applicationName,
pageTitle,
}: {
applicationName: string;
pageTitle: string
}) => {
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.reportTitle);
let windowTitle = await nvdaPlaywright.lastSpokenPhrase();

if (windowTitle.includes(applicationName)) {
if (hasFocus({applicationName, pageTitle, windowTitle})) {
return;
}

Expand All @@ -78,7 +89,7 @@ const focusBrowser = async ({
await nvdaPlaywright.perform(nvdaPlaywright.keyboardCommands.reportTitle);
windowTitle = await nvdaPlaywright.lastSpokenPhrase();

if (windowTitle.includes(applicationName)) {
if (hasFocus({applicationName, pageTitle, windowTitle})) {
break;
}
}
Expand Down Expand Up @@ -139,8 +150,9 @@ export const nvdaTest = test.extend<{
nvdaPlaywright.keyboardCommands.exitFocusMode
);

const pageTitle = await page.title();
// Ensure application is brought to front and focused.
await focusBrowser({ applicationName });
await focusBrowser({ applicationName, pageTitle });

// NVDA appears to not work well with Firefox when switching between
// applications resulting in the entire browser window having NVDA focus
Expand Down
Loading