Skip to content

Instrumenting your Application for Calabash iOS

Joshua Moody edited this page Jun 17, 2015 · 5 revisions

To get the most from Calabash iOS, you should instrument your app for testing.

Xamarin Studio users can find more information on the Custom Controls with Xamarin Studio, and Accessibility for Calabash iOS page.

Don't be confused: instrumenting your app has nothing to do with Apple's Instruments.app or the instruments command line tool. When you instrument an app, you add information and behaviors that make it easy to gain insights into the runtime behavior of an application.

There are two categories of instrumentation that can improve your Calabash iOS testing experience.

  1. Add meaning Accessibility properties to your UIView instances.
  2. Use backdoors to implement complex behaviors that are usually achieved by complex UI interactions.

Accessibility Properties

Queries that use the marked: syntax search your app for views with matching accessibilityIdentifiers and accessibilityLabels. marked: will also match on text, but let's put that aside for now.

Whenever possible, use accessibilityIdentifier instead of accessibilityLabel. Accessibility labels are used for Voice Over. As such, they should be localized and should follow a specific capitalization format to assist Voice Over enunciation.

For more information about Accessibility Label best practices, see the Apple documentation

Add Identifiers in Code

  button.accessibilityIdentifier = @"center-to-location";
  button.accessibilityLabel = @"Center map";

  switch.accessibilityIdentifier = @"coffee need refill?";
  button.accessibilityLabel = @"Refill coffee?";

  webView.accessibilityIdentifier = @"landing page";
  webView.accessibilityLabel = NSLocalizedString(@"Landing page", 
                                                 @"The web view start page.");

Use Interface Builder to Add Identifiers

2015-04-07_11-41-08

===

Other Resources

The WWDC 2013 video is highly recommended because it contains an excellent demonstration.

  1. WWDC 2013 Accessibility on iOS. HD SD
  2. WWDC 2014 Accessibility on iOS HD SD

Special Case: UIBarButtonItem

Buttons in UIToolbars and UINavigationBars are generated at runtime from UIBarButtonItem instances. There is no way to set the accessibilityIdentifier on a UIBarButtonItem instance and have it apply to the button that is created at runtime. Further, UIKit will often overwrite an accessibilityLabel that you put on UIBarButtonItem instances. The exception is when the item is created using the initWithCustomView: selector; items created with this selector often respect labels and identifiers at runtime.

Backdoors

Content in progress.

Custom Calabash Plug-Ins

Content in progress.

Clone this wiki locally