KEMBAR78
Effectively Using UI Automation | KEY
# obj cgn  12”
         cial tag:        “Obj CGN
    Offi         ac/iPad”:
           ne/M
 i-Fi “iPho
W
EFFECTIVELY USING UIAUTOMATION
           Alexander Repty
WHY AUTOMATE?
WHY AUTOMATE?
WHY AUTOMATE?
WHY AUTOMATE?
WHY AUTOMATE?


   “[…] the three great virtues of a
 programmer: laziness, impatience, and
               hubris.”

Larry Wall, Programming Perl,1991
WHAT ARE AUTOMATED TESTS?
WHAT ARE AUTOMATED TESTS?
WHAT ARE AUTOMATED TESTS?


•   Drive UI without any human interference
WHAT ARE AUTOMATED TESTS?


•   Drive UI without any human interference

•   A little like unit tests for GUI
WHAT ARE AUTOMATED TESTS?


•   Drive UI without any human interference

•   A little like unit tests for GUI

•   Log progress (passes & fails)
WHAT ARE AUTOMATED TESTS?


•   Drive UI without any human interference

•   A little like unit tests for GUI

•   Log progress (passes & fails)

•   Find out quickly when something breaks
WHAT ELSE CAN UI AUTOMATION DO?
WHAT ELSE CAN UI AUTOMATION DO?


•   Automate annoying tasks
WHAT ELSE CAN UI AUTOMATION DO?


•   Automate annoying tasks

•   Demo your product
WHAT ELSE CAN UI AUTOMATION DO?


•   Automate annoying tasks

•   Demo your product

•   Quickly perform tasks multiple times
WHAT ELSE CAN UI AUTOMATION DO?


•   Automate annoying tasks

•   Demo your product

•   Quickly perform tasks multiple times

•   Screenshots and screencasts
WHY USE UIAUTOMATION OVER
   OTHER FRAMEWORKS?
WHY USE UIAUTOMATION OVER
            OTHER FRAMEWORKS?


•   Instantly available for everyone
WHY USE UIAUTOMATION OVER
            OTHER FRAMEWORKS?


•   Instantly available for everyone

•   Easy to set up and use
WHY USE UIAUTOMATION OVER
            OTHER FRAMEWORKS?


•   Instantly available for everyone

•   Easy to set up and use

•   Improves application accessibility
UIAUTOMATION EXAMPLE
UIAUTOMATION EXAMPLE
UIAUTOMATION EXAMPLE


•   Not accessible yet
UIAUTOMATION EXAMPLE


•   Not accessible yet

•   Never used UIAutomation on it
UIAUTOMATION EXAMPLE


•   Not accessible yet

•   Never used UIAutomation on it

•   Let’s see how quickly we can make it work
GENERATED CODE
GENERATED CODE
GENERATED CODE
GENERATED CODE
GENERATED CODE
GENERATED CODE
GENERATED CODE


•   Hard to read
GENERATED CODE


•   Hard to read

•   Harder to edit
GENERATED CODE


•   Hard to read

•   Harder to edit

•   Impossible to maintain on a large scale
GENERATED CODE


•   Hard to read

•   Harder to edit

•   Impossible to maintain on a large scale

•   Solution: Use Accessibility APIs!
IMPLEMENTING ACCESSIBILITY
IMPLEMENTING ACCESSIBILITY
IMPLEMENTING ACCESSIBILITY

•   Enable accessibility
IMPLEMENTING ACCESSIBILITY

•   Enable accessibility

•   Assign an accessibility label
IMPLEMENTING ACCESSIBILITY

•   Enable accessibility

•   Assign an accessibility label

•   Optional: add an accessibility hint
IMPLEMENTING ACCESSIBILITY

•   Enable accessibility

•   Assign an accessibility label

•   Optional: add an accessibility hint

•   Optional: assign accessibility traits
IMPLEMENTING ACCESSIBILITY
IMPLEMENTING ACCESSIBILITY
IMPLEMENTING ACCESSIBILITY
IMPLEMENTING ACCESSIBILITY

     Before:
     […].textFields()[0].tap();
IMPLEMENTING ACCESSIBILITY

     Before:
     […].textFields()[0].tap();

     After:
     […].textFields()["Item Title"].tap();
IMPLEMENTING ACCESSIBILITY
IMPLEMENTING ACCESSIBILITY

   Before:
    […].tapWithOptions({tapOffset:{x:0.25, y:0.33}});
IMPLEMENTING ACCESSIBILITY

   Before:
    […].tapWithOptions({tapOffset:{x:0.25, y:0.33}});


    After:
    […].buttons()["Fruit"].tap();
IMPLEMENTING ACCESSIBILITY
IMPLEMENTING ACCESSIBILITY

    What did I do?
    ! self.isAccessibilityElement = YES;
IMPLEMENTING ACCESSIBILITY

    What did I do?
    ! self.isAccessibilityElement = YES;
    ! self.accessibilityLabel = item.title;
IMPLEMENTING ACCESSIBILITY

    What did I do?
    ! self.isAccessibilityElement = YES;
    ! self.accessibilityLabel = item.title;
    ! self.accessibilityTraits =
          (UIAccessibilityTraitButton);
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE

   UISegmentedControl accessibility sucks.
(SLIGHTLY) BETTER CODE
(SLIGHTLY) BETTER CODE


•   Check your view hierarchy (use logElementTree())
(SLIGHTLY) BETTER CODE


•   Check your view hierarchy (use logElementTree())

•   Find weaknesses and accessibility flaws in your code
(SLIGHTLY) BETTER CODE


•   Check your view hierarchy (use logElementTree())

•   Find weaknesses and accessibility flaws in your code

•   Write tests that last
IMPROVE ACCESSIBILITY
IMPROVE ACCESSIBILITY
IMPROVE ACCESSIBILITY
IMPROVE ACCESSIBILITY
IMPROVE ACCESSIBILITY
IMPROVE ACCESSIBILITY


•   Excellent article by Matt Gemmell

    http://mattgemmell.com/2010/12/19/accessibility-for-iphone-and-ipad-apps/
IMPROVE ACCESSIBILITY


•   Excellent article by Matt Gemmell

    http://mattgemmell.com/2010/12/19/accessibility-for-iphone-and-ipad-apps/

•   Even Apple links to it
IMPROVE ACCESSIBILITY


•   Excellent article by Matt Gemmell

    http://mattgemmell.com/2010/12/19/accessibility-for-iphone-and-ipad-apps/

•   Even Apple links to it

•   Essential for proper automation; two birds with one stone
TESTING YOUR UI
TESTING YOUR UI
TESTING YOUR UI


•   UIALogger (logMessage, logStart, logPass, logFail)
TESTING YOUR UI


•   UIALogger (logMessage, logStart, logPass, logFail)

•   No built-in support for assertions (TuneUp JS)
TESTING YOUR UI


•   UIALogger (logMessage, logStart, logPass, logFail)

•   No built-in support for assertions (TuneUp JS)

•   Works with continuous integration systems (using Instruments CLI
    command)
TESTING YOUR UI
TESTING YOUR UI
TESTING YOUR UI
TESTING YOUR UI
RUNNING MULTIPLE TESTS
RUNNING MULTIPLE TESTS
RUNNING MULTIPLE TESTS


•   Run three separate tests
RUNNING MULTIPLE TESTS


•   Run three separate tests

    •   Add & delete Spaghetti
RUNNING MULTIPLE TESTS


•   Run three separate tests

    •   Add & delete Spaghetti

    •   Go to yesterday, add and delete a Steak
RUNNING MULTIPLE TESTS


•   Run three separate tests

    •   Add & delete Spaghetti

    •   Go to yesterday, add and delete a Steak

    •   Add an item, tweet it and delete it
MORE THINGS YOU CAN DO
MORE THINGS YOU CAN DO
MORE THINGS YOU CAN DO

•   Handle unexpected & expected alerts
MORE THINGS YOU CAN DO

•   Handle unexpected & expected alerts

•   Multitasking (deactivate app for any given duration)
MORE THINGS YOU CAN DO

•   Handle unexpected & expected alerts

•   Multitasking (deactivate app for any given duration)

•   Orientation changes
MORE THINGS YOU CAN DO

•   Handle unexpected & expected alerts

•   Multitasking (deactivate app for any given duration)

•   Orientation changes

•   Set location
MORE THINGS YOU CAN DO

•   Handle unexpected & expected alerts

•   Multitasking (deactivate app for any given duration)

•   Orientation changes

•   Set location

•   Gestures
MORE THINGS YOU CAN DO
MORE THINGS YOU CAN DO

•   Take screen shots
MORE THINGS YOU CAN DO

•   Take screen shots

    •   Automate screen shots for the App Store
MORE THINGS YOU CAN DO

•   Take screen shots

    •   Automate screen shots for the App Store

    •   Even in multiple languages!
MORE THINGS YOU CAN DO

•   Take screen shots

    •   Automate screen shots for the App Store

    •   Even in multiple languages!

•   Easily reproducible screen casts (with perfect timing)
MORE THINGS YOU CAN DO

•   Take screen shots

    •   Automate screen shots for the App Store

    •   Even in multiple languages!

•   Easily reproducible screen casts (with perfect timing)

•   Document your test runs
MORE THINGS YOU CAN DO
MORE THINGS YOU CAN DO
MORE THINGS YOU CAN DO
MORE THINGS YOU CAN DO
MORE THINGS YOU CAN DO
WHAT’S NOT SO GOOD ABOUT
     UIAUTOMATION?
WHAT’S NOT SO GOOD ABOUT
              UIAUTOMATION?

•   No way to set up or reset state (may have to exit on fail)
WHAT’S NOT SO GOOD ABOUT
              UIAUTOMATION?

•   No way to set up or reset state (may have to exit on fail)

•   Only runs via Instruments
WHAT’S NOT SO GOOD ABOUT
              UIAUTOMATION?

•   No way to set up or reset state (may have to exit on fail)

•   Only runs via Instruments

•   Might need arcane shell scrips to integrate into CI tools
WHAT’S NOT SO GOOD ABOUT
              UIAUTOMATION?

•   No way to set up or reset state (may have to exit on fail)

•   Only runs via Instruments

•   Might need arcane shell scrips to integrate into CI tools

•   No built-in method for mock objects
WHAT’S NOT SO GOOD ABOUT
              UIAUTOMATION?

•   No way to set up or reset state (may have to exit on fail)

•   Only runs via Instruments

•   Might need arcane shell scrips to integrate into CI tools

•   No built-in method for mock objects

•   Very young, still maturing
WHAT ELSE IS THERE?
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
WHAT ELSE IS THERE?

Product        Good           Bad            Ugly
             Languages
 Squish                    Commercial       Eclipse
             Platforms

  KIF        Objective-C   Private API      Setup

               Natural
Calabash                     Setup       Client/Server
              Language
SUMMARY
SUMMARY
SUMMARY


•   Automated testing is awesome
SUMMARY


•   Automated testing is awesome

•   Better with accessibility support
SUMMARY


•   Automated testing is awesome

•   Better with accessibility support

•   Build cases to test your application’s features
SUMMARY


•   Automated testing is awesome

•   Better with accessibility support

•   Build cases to test your application’s features

•   Automate repetitive tasks
SUMMARY
SUMMARY


Spend less time testing,
more time doing
important stuff
SUMMARY


Spend less time testing,
more time doing
important stuff
FURTHER READING
FURTHER READING
•   Jonathan Penn

    •   http://cocoamanifest.net/

    •   “jonathanpenn” on Twitter and Github

•   Alex Vollmer

    •   http://alexvollmer.com

    •   “alexvollmer” on Twitter and Github
FURTHER READING
FURTHER READING
•   Shaun Ervine - Automated Acceptance Tests with UIAutomation, Jasmine &
    Jenkins

    •   http://shaune.com.au/automated-ui-testing-for-ios-apps-uiautomation-
        jasmine-jenkins/
FURTHER READING
•   Shaun Ervine - Automated Acceptance Tests with UIAutomation, Jasmine &
    Jenkins

    •   http://shaune.com.au/automated-ui-testing-for-ios-apps-uiautomation-
        jasmine-jenkins/

•   Philipp Haussleiter - Using UIAutomation for Multilanguage iOS Applications

    http://www.innoq.com/blog/phaus/2011/01/using_uiautomation_for_multila.html
FURTHER READING
•   Shaun Ervine - Automated Acceptance Tests with UIAutomation, Jasmine &
    Jenkins

    •   http://shaune.com.au/automated-ui-testing-for-ios-apps-uiautomation-
        jasmine-jenkins/

•   Philipp Haussleiter - Using UIAutomation for Multilanguage iOS Applications

    http://www.innoq.com/blog/phaus/2011/01/using_uiautomation_for_multila.html

•   Apple

    •   UI Automation Reference Library & WWDC Session Videos
THANK YOU!

 I’d love to hear from you.
alexander.repty@mac.com
           @arepty
PHOTO CREDITS
PHOTO CREDITS

•   “Lazy Dog” by Hector Garcia (http://www.flickr.com/photos/torek/2467519466/)

•   “There Isn’t An App For That” by Martha Soukup (http://www.flickr.com/photos/
    soukup/5157648804/)

•   “Titanic” by Javier Carcamo (http://www.flickr.com/photos/javic/7081573725/)

•   “Tesla Motors Assembly Line” by Steve Jurvetson (http://www.flickr.com/photos/
    jurvetson/6858583426/)
# obj cgn  12”
         cial tag:        “Obj CGN
    Offi         ac/iPad”:
           ne/M
 i-Fi “iPho
W




                                    This must be
                                    the last page.

Effectively Using UI Automation