API Reference

Link to API Reference copied to clipboard

The API Reference for the @axe-core/watcher package

Free Trial

This reference guide describes the classes and functions provided by the @axe-core/watcher package.

Controller Classes

All of the classes in this section allow you to manually control the accessibility analysis of the pages.

Name Description
PlaywrightController Allows manual control of a Playwright test run
PuppeteerController Allows manual control of a Puppeteer test run
WdioController Allows manual control of a WebdriverIO test run
WebdriverController Allows manual control of a Selenium test run
note

For Cypress, the common methods in the *Controller classes are implemented as custom commands. See Controller Custom Commands for Cypress for more information.

PlaywrightController

The PlaywrightController class allows you to manually control test runs with Playwright. You can start and stop automatic accessibility analysis as well as analyze pages that require additional setup.

For more information about Playwright, see the Playwright Documentation.

Constructor

new PlaywrightController(driver: Page): PlaywrightController
Parameters

The driver value is a Playwright Page object.

Returns PlaywrightController

Methods

analyze
analyze(): Promise<void>

Analyzes the current page for accessibility errors. You call this method after you have set up a webpage for analysis (such as entered values in a form) and have turned off automatic analysis using the stop method.

Returns Promise<void>
flush
flush(): Promise<void>

Sends all of the results of the accessibility scan to the server. Should be called at the end of the test run to be certain the results have been sent to the server.

start
start(): Promise<void>

Resumes autoanalysis of webpages. You call this method when you want to resume autoanalyzing webpages for accessibility errors.

Returns Promise<void>
stop
stop(): Promise<void>
Returns Promise<void>

Stops autoanalysis of webpages. After you call the stop method, you can do any additional set up that your webpage may require and then call the analyze method to check the page for accessibility errors.

PuppeteerController

The PuppeteerController class allows manual control of your testing runs with Puppeteer. Manual control allows you to provide additional setup required by more complex webpages.

For more information about Puppeteer, see Puppeteer.

Constructor

new PuppeteerController(driver: Page): PuppeteerController
Parameters

The driver value is a Puppeteer Page object.

Returns PuppeteerController

Methods

analyze
analyze(): Promise<void>

Analyzes the current page for accessibility errors. You call this method after you have set up a webpage for analysis (such as entered values in a form) and have turned off automatic analysis using the stop method.

Returns Promise<void>
flush
flush(): Promise<void>

Sends all of the results of the accessibility scan to the server. Should be called at the end of the test run to be certain the results have been sent to the server.

start
start(): Promise<void>

Resumes autoanalysis of webpages. You call this method when you want to resume autoanalyzing webpages for accessibility errors.

Returns Promise<void>
stop
stop(): Promise<void>
Returns Promise<void>

Stops autoanalysis of webpages. After you call the stop method, you can do any additional set up that your webpage may require and then call the analyze method to check the page for accessibility errors.

WdioController

The WdioController allows you to manually control test WebdriverIO test runs. For pages that require additional setup or configuration, you can stop automatic testing and manually analyze each page that requires such setup.

Constructor

new WdioController(driver: Page): WdioController
Parameters
  • driver: Browser
Returns WdioController

Methods

analyze
analyze(): Promise<void>

Analyzes the current page for accessibility errors. You call this method after you have set up a webpage for analysis (such as entered values in a form) and have turned off automatic analysis using the stop method.

Returns Promise<void>
flush
flush(): Promise<void>

Sends all of the results of the accessibility scan to the server. Should be called at the end of the test run to be certain the results have been sent to the server.

start
start(): Promise<void>

Resumes autoanalysis of webpages. You call this method when you want to resume autoanalyzing webpages for accessibility errors.

Returns Promise<void>
stop
stop(): Promise<void>
Returns Promise<void>

Stops autoanalysis of webpages. After you call the stop method, you can do any additional set up that your webpage may require and then call the analyze method to check the page for accessibility errors.

WebdriverController

Constructor

new WebdriverController(driver: Page): WebdriverController
Parameters

The driver value is a Selenium WebDriver object.

Returns WebdriverController

Methods

analyze
analyze(): Promise<void>

Analyzes the current page for accessibility errors. You call this method after you have set up a webpage for analysis (such as entered values in a form) and have turned off automatic analysis using the stop method.

Returns Promise<void>
flush
flush(): Promise<void>

Sends all of the results of the accessibility scan to the server. Should be called at the end of the test run to be certain the results have been sent to the server.

start
start(): Promise<void>

Resumes autoanalysis of webpages. You call this method when you want to resume autoanalyzing webpages for accessibility errors.

Returns Promise<void>
stop
stop(): Promise<void>
Returns Promise<void>

Stops autoanalysis of webpages. After you call the stop method, you can do any additional set up that your webpage may require and then call the analyze method to check the page for accessibility errors.

Cypress Custom Commands

In the Cypress browser automation platform, the methods in the *Controller classes are implemented as custom commands. See Custom Commands on the Cypress documentation site for more information about implementing and using custom commands.

The following commands are implemented. Each command returns Chainable<void> to allow chaining with other Cypress commands.

Controller Method Equivalent Cypress Command
flush() axeFlush()

These additional Cypress commands allow access to internal Cypress values:

  • state()

    Internal Cypress state.

  • subject

    The current Cypress subject. See Subject Management in the Cypress documentation for more information.

Cypress Command Example

The following example shows how to import the axe Developer Hub's Cypress commands from the @axe-core/watcher package and then call the axeFlush command at the end of each test (by placing it inside afterEach()):

// Import the axe-watcher commands.
require('@axe-core/watcher/dist/cypressCommands')

// Flush axe-watcher results after each test.
afterEach(() => {
  cy.axeFlush()
})

Config Functions

The functions provided by the @axe-core/watcher package create configurations for use by the specified integration.

Function Description
cypressConfig Creates a configuration for Cypress
playwrightConfig Creates a configuration for Playwright.
puppeteerConfig Creates a configuration for Puppeteer.
wdioConfig Creates a configuration for WebdriverIO.
webdriverConfig Creates a configuration for Selenium WebDriver.

cypressConfig

cypressConfig(config: Cypress.ConfigOptions & Configuration): Cypress.ConfigOptions

Creates a config for Cypress.

Parameters

  • config: Cypress.ConfigOptions & Configuration

Cypress config to extend.

Returns Cypress.ConfigOptions

playwrightConfig

playwrightConfig(opts: Configuration & LaunchOptions): LaunchOptions

Creates a config for Playwright.

Parameters

  • opts: Configuration & LaunchOptions

Playwright config to extend

Returns LaunchOptions

puppeteerConfig

puppeteerConfig(opts: Configuration & LaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions): Options

Creates a config for Puppeteer.

Parameters

  • opts: Configuration & LaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions

The configuration you'd like to extend.

Returns Options

wdioConfig

wdioConfig(arg): RemoteOptions

Creates a WebdriverIO configuration.

Parameters

  • arg: RemoteOptions & Configuration

The WebdriverIO config to extend.

Returns: RemoteOptions

webdriverConfig

webdriverConfig(arg: WebDriverArgs): Options

Creates a Selenium WebDriver configuration.

Parameters

  • arg: WebDriverArgs

The Selenium WebDriver configuration to extend

Returns Options