Skip to content

ScreenReader

Damyon Wiese edited this page Jun 22, 2017 · 5 revisions

The ScreenReader API is the entire point of this test suite. By limiting us to functionality that is available to screen readers - it will force developers to think about creating a website that is not just functional for screen readers - but is actually nice to use. If it is hard to write these tests - it's probably a sign that your website is hard to use.

Types

ScreenReader

ScreenReader is the class you use to interact with the API. An instance of this class is created for you before your test is run and is available through the "reader" global variable.

NodeWrapper

Whenever a function in the ScreenReader API requires or returns a node from the accessibility tree - it is wrapped in a "NodeWrapper" class. This class is meant to be opaque and you should not ever have to know what is inside it. This is intentional so that you don't get access to more information and functionality than a screen reader would normally have (no DOM, no CSS selectors etc).

Methods

A note about methods. The ones marked async actually return a Promise - but you can just wait for the promise with "await" because this is Chrome 59 and we are allowed to have nice things.

getFocus (async)

This function returns a NodeWrapper representing the node in the accessibility that currently has focus. Will return undefined if no node currently has focus.

Params

  • None

Return

  • NodeWrapper|undefined

getPageTitle (async)

This function returns the title of the current page. Will return undefined if the page has not defined a title.

Params

  • None

Return

  • string|undefined

findInPage (async)

This function searches the accessibility tree for the first node matching the search criteria. Will return undefined if there is no match. Note: regexes are supported for name searches.

An example of a search is: { name: /Home/, role: 'link'}

Params

  • Object attributes containing attribute name/values.

Return

  • NodeWrapper|undefined

existsInPage (async)

This function searches the accessibility tree for any node matching the search criteria. Will return true or false. Note: regexes are supported for name searches.

An example of a search is: { name: /Home/, role: 'link'}

Params

  • Object attributes containing attribute name/values.

Return

  • boolean

find

This function searches the accessibility tree starting from the specified node for any node matching the search criteria. Searches will only match the subtree and will not continue to search the parent nodes. Will return a NodeWrapper or undefined. Note: regexes are supported for name searches.

An example of a search is: { name: /Home/, role: 'link'}

Params

  • NodeWrapper node The root of the subtree for the search.
  • Object attributes containing attribute name/values.

Return

  • NodeWrapper|undefined

next

This function scans the accessibility tree sequentially starting from the specified node for any node matching the search criteria. Searches will start by matching on the subtree, but will continue to the parents of the specified node. Will return a NodeWrapper or undefined. Note: regexes are supported for name searches. Note: This function is expensive if there is no match.

An example of a search is: { name: /Home/, role: 'link'}

Params

  • NodeWrapper node The starting node for the search.
  • Object attributes containing attribute name/values.

Return

  • NodeWrapper|undefined

focus

This function will shift focus to the specified node.

Params

  • NodeWrapper node The node which will take the focus.

Return

  • None

doDefault (async)

This function will perform the default action (e.g. click, select) the specified node. Note: It is important to wait for the return of this function as it will wait e.g. for the next page to start responding to the action.

Params

  • NodeWrapper node The node which will be acted upon.

Return

  • None

isFocusable

This function will test to see if the specified node can receive focus.

Params

  • NodeWrapper node The node which will be checked.

Return

  • boolean

isExpanded

This function will test to see if the specified node is expanded (e.g. a menu is open).

Params

  • NodeWrapper node The node which will be checked.

Return

  • boolean

isVisible

This function will test to see if the specified node is visible (e.g. not aria-hidden).

Params

  • NodeWrapper node The node which will be checked.

Return

  • boolean

getAccessibleName

This function will get the accessible name for the node as determined by the ARIA spec.

Params

  • NodeWrapper node The node which will be examined.

Return

  • string|undefined

debugPrintTree (async)

This function prints debug information about the entire accessibility tree. Use -v to see this debug output on the console.

Params

  • NodeWrapper node The node which will be examined.

Return

  • None

debugPrintNode

This function prints some debug information about this accessibility node. Use -v to see this debug output on the console.

Params

  • NodeWrapper node The node which will be examined.

Return

  • None

Clone this wiki locally