Skip to main content
Version: v3

Writing Custom Accessibility Tests

The AudioEye Accessibility Testing SDK allows you to write custom tests using the @audioeye/testing-sdk-core package. This package provides the core functionality used for all of our testing frameworks. If specific framework coverage is not provided, you can use this package to write your own tests.

If you need to setup a virtual browser environment, you can use the @audioeye/testing-sdk-virtual-dom package.

If you need to convert the test results to a different format, you can use the @audioeye/testing-sdk-results package.

Pre-requisites

Visit the Getting Started guide to install the SDK and set up your project.

Usage

Use the findIssues function to run your custom tests. This function can be imported from @audioeye/testing-sdk-core. The return type of this function is a TestingSdkAllResultType.

Importing the function

import { findIssues } from '@audioeye/testing-sdk-core';

findIssues type signature

import type { RenderResult } from '@testing-library/react';

type EvaluateRulesInputType = string | RenderResult | HTMLElement | DocumentFragment | JQuery<HTMLElement>;

type RunOptions = {
browserMode: 'virtual' | 'real';
runMode: 'external' | 'embedded';
resultsToFilter?: Set<string>;
component?: boolean;
printTestList?: boolean;
debug?: boolean;
format?: 'html' | 'json' | 'csv';
viewportDimensions?: {
width: number;
height: number;
};
mobile?: boolean;
output?: string;
stdout?: boolean;
timeout?: number;
cssSelectors?: boolean;
localWindow?: Window;
metadataToExclude?: (keyof RuleMetaOutput)[];
};

type TestingSdkAllResultType = {
ruleResults: TestingSdkRuleResultType[];
exitCode: number;
summaryResults: string;
formattedResults: string;
};

type TestingSdkRuleResultType = {
ruleCode: string;
ruleMetadata: RuleMetaOutput | undefined;
result: string;
source: string;
cssSelector?: string;
};

type RuleMetaOutput = {
code: string;
description: string;
fixAtSource: boolean;
fullName: string;
sourceFixGuidance?: string;
wcagSuccessCriteriaLevelCode: string;
wcagSuccessCriteriaName: string;
wcagSuccessCriteriaNumber: string;
};

declare const findIssues: (partialRunOptions?: Partial<RunOptions>) => TestingSdkAllResultType;

declare const setupDocument: (
input: EvaluateRulesInputType,
{
isRealBrowser,
localWindow,
}?: {
isRealBrowser?: boolean | null | undefined;
localWindow?: Window | null | undefined;
},
) => () => void;

declare function isHTMLHtmlElement(input: EvaluateRulesInputType): boolean;

declare const addFormattedResults: (
results: TestingSdkAllResultType,
{ runMode, format }: RunOptions,
url?: URL,
) => TestingSdkAllResultType;

Example

import { findIssues } from '@audioeye/testing-sdk-core';
import { setupDocument } from '@audioeye/testing-sdk-virtual-dom';

// If you do not have a real browser environment, you can use setupDocument function to create a virtual DOM.
const cleanup = setupDocument(document.body);
let a11yIssues = findIssues({ component: !isHTMLHtmlElement(document.body) });

// Clean up the virtual DOM
cleanup();

// Add CSV to the results
a11yIssues = addFormattedResults(a11yIssues, { format: 'csv' });

// Handle the results
const { ruleResults, exitCode, summaryResults, formattedResults } = a11yIssues;