Testing for Accessibility on OS X

Whether you’re designing a new app or access-enabling an existing one, you should plan to test the accessibility of your product. Testing for accessibility is a bit different than standard user interface testing, and Apple provides a couple of tools that make the process easier. After you’ve discovered accessibility bugs with VoiceOver, inspect your app with these tools to resolve the problems.

App developers should read this chapter to find out how to exercise the accessibility of their apps.

Using the Accessibility Inspector

Apple provides the Accessibility Inspector testing tool that can be launched by choosing Xcode > Open Developer Tool > Accessibility Inspector in the menu bar or Dock. You can download Xcode from the Mac App Store for free. The Accessibility Inspector presents a utility window that displays the information properties (and values), action methods, and position in the accessibility hierarchy of the object currently under the mouse pointer.

If you’re beginning to access-enable your app for assistive technologies like VoiceOver, try using the Accessibility Inspector to view the accessibility information other apps provide. Although the Accessibility Inspector is not an accessibility client, it uses the same APIs accessibility clients use to get information from the accessibility objects it encounters.

To use the Accessibility Inspector, first make sure that it has permission to control your computer. In Security & Privacy preferences, open the Privacy pane. In the left column, select the Accessibility option. In the right column, make sure the Accessibility Inspector app is checked as shown in Figure 6-1.

Figure 6-1  Enabling the Accessibility Inspector

Now, launch the Accessibility Inspector and move your mouse over the UI element you want to inspect. If you’re using VoiceOver to navigate, you can move the mouse to the VoiceOver cursor by pressing Control-Option-Command-F5. You can lock the Accessibility Inspector on the item under the mouse to examine its attributes, perform its actions, and access its parent and children (if any), by pressing Command-F7. When you do this, the Accessibility Inspector display pauses, allowing you to move the mouse without changing the object on which the tool is focused. In the main utility window, you can go to the object’s parent, children, or other related objects, such as the containing window or the top-level app (AXApplication). You can also perform the actions supported by the accessibility object, allowing you to see how these actions affect the values of various attributes and the app itself. If you click the rectangular button in the bottom-right corner of the Accessibility Inspector panel, you’ll see a light blue overlay over the locked UI element.

Figure 6-2 shows the Accessibility preferences icon locked. In this example, the AXPress action for the element is selected and can be activated by clicking the Perform Action button.

Figure 6-2  The Accessibility Inspector locked on the Accessibility icon in System Preferences

The Accessibility Inspector also includes the ability to navigate the Accessibility tree hierarchy using visible buttons or keyboard commands. While holding the Control and Command keys, use the arrow keys to navigate. The up and down arrows navigate to parents or children, and the left and right arrows navigate to siblings of the current element.

You can use the Accessibility Inspector to modify any properties that are marked as writable, as denoted by a W in parentheses. For example, navigate up to the AXWindow attribute, and select its AXPosition property (see Figure 6-3). Change the values of the X and Y text fields, and click the Set Value button. The window changes its position on the screen. You can also perform certain actions, such as AXPress and AXShowMenu, by selecting the action and clicking the Perform Action button.

Figure 6-3  The Accessibility Inspector locked on the System Preferences main window

As you access-enable your app, use the Accessibility Inspector to make sure your objects contain the appropriate information. If you find that a specific object is not accessible, you can focus the Accessibility Inspector on that object, examine its information property values, and trigger its action methods to find the problem.

Using Accessibility Verifier

Apple provides the Accessibility Verifier tool that can be launched by choosing Accessibility Inspector > Window > Accessibility Verifier. Accessibility Verifier displays the accessibility hierarchy comprising all currently instantiated objects in the selected app. To use Accessibility Verifier, be sure to enable it in Security & Privacy preferences.

Use Accessibility Verifier to perform any or all of the following tests (select the tests you want to run by clicking the Choose Tests button):

When you click Verify, Accessibility Verifier runs the tests you selected and displays the results for each. The problems are reported as warnings or errors, depending on their severity (you can filter the results by selecting a severity level in the Report Level pop-up menu).

Eliminating all errors and warnings that Accessibility Verifier displays does not guarantee a perfectly accessible app. Always test your app with various accessibility clients, such as VoiceOver, to make sure there are no problems.