BT

Google Open Sources Accessibility Test Framework for iOS

| by Sergio De Simone Follow 14 Followers on Apr 04, 2018. Estimated reading time: 1 minute |

Google GTXiLib, an accessibility test automation framework for iOS, is now open source under the Apache License. GTXiLib is written in Objective-C and integrates with Xcode.

The way GTXiLib integrates with Xcode is through the XCTest unit testing framework. You can install GTXiLib for any of your test classes and register a number of accessibility checks you would like to be performed together with your unit tests. If any accessibility check fails, the corresponding unit test will also fail.

The accessibility checks that GTXiLib currently supports aim to ensure that labels are present on buttons, that labels are not punctuated, that tappable areas have a minimum area, and text contrast is high enough.

GTXiLib also provides the means for developers to build their own custom checks. This is possible by using the checkWithName:block: API. The following is a simplified version of an accessibility check to ensure that a label is present on an element:

  id<GTXChecking> check = [GTXCheckBlock GTXCheckWithName:"LabelMustBePresent"
                                   block:^BOOL(id element, GTXErrorRefType errorOrNil) {

    NSError *error;
    id accessibilityLabel = [element accessibilityLabel];
    if (![accessibilityLabel isKindOfClass:[NSString class]]) {
        *errorOrNil = // set error;
      }
      // Fail
      return NO;
    }
    return NO;
  }];

As it turns out, low-level accessibility checks are made possible by Apple’s own UIAccessibility framework, as exemplified by the use of the accessibilityLabel property in the above example. GTXiLib tests are not limited to using only UIAccessibility methods, though, and may use any available framework for their inner workings.

To install GTXiLib for one of your test classes, just add the following line of code to its +setup method:

+ (void)setUp {
  [super setUp];

  // ... your other setup code (if any) comes here.

  // Install GTX on all tests in *this* test class.
  [GTXiLib installOnTestSuite:[GTXTestSuite suiteWithAllTestsInClass:self]
                       checks:[GTXChecksCollection allGTXChecks]
            elementBlacklists:@[]];
}

By doing this, all accessibility checks will be run for each of the unit tests defined in that test class. If you want to exclude a number of UI elements from accessibility checks, you can list them in the elementBlackLists array. This is a useful resource when you are trying to retrofit accessibility tests to an existing codebase, so you can exclude elements that you cannot control or those that will be fixed at some later point in time.

Being based on XCTest makes GTXiLib compatible with any XCTest-based framework, such as Google’s own UI Automation test framework EarlGrey.

GTXiLib can be easily added to a project using cocoapods.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT