Skip to content
Merged
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
22 changes: 19 additions & 3 deletions src/nvdaTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,27 @@ type FocusBrowserParams = {
pageTitle: string;
};

const cleanString = (str: string): string =>
str
.toLowerCase()
// REF: https://github.com/nvaccess/nvda/blob/master/source/locale/en/symbols.dic
.replace(/[|¦:;'"`\-‐–—·_()[\]{}\\^~]/g, " ")
.replace(/\s+/g, " ")
.trim();

const hasFocus = ({
applicationName,
pageTitle,
windowTitle,
}: FocusBrowserParams & { windowTitle: string }) => {
const cleanedApplicationName = cleanString(applicationName);
const cleanedPageTitle = cleanString(pageTitle);
const cleanedWindowTitle = cleanString(windowTitle);

return (
(pageTitle.length && windowTitle.startsWith(pageTitle)) ||
windowTitle.includes(applicationName)
(cleanedPageTitle.length &&
cleanedWindowTitle.startsWith(cleanedPageTitle)) ||
cleanedWindowTitle.includes(cleanedApplicationName)
);
};

Expand Down Expand Up @@ -161,7 +174,10 @@ export const nvdaTest = test.extend<{

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

// Ensure the document is ready and focused.
await page.bringToFront();
Expand Down
Loading