Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scalable and Collaborative UI Test Automation i...

Scalable and Collaborative UI Test Automation in Swift

Presented at Mobile Dev + Test 2016, San Diego, CA, 04/21/2016.
https://mobiledevtest.techwell.com/program/concurrent-sessions/scalable-and-collaborative-ios-ui-test-automation-swift

Write *good* UI automation for your iOS apps and get your devs + testers collaborating. And, hopefully, stop shipping so many bugs. :)

Avatar for Jason Hagglund

Jason Hagglund

April 21, 2016
Tweet

Other Decks in Technology

Transcript

  1. Scalable and Collaborative UI Test Automation in Swift Jason Hagglund

    Staff Software Eng - Test, The Climate Corporation https://github.com/TheMetalCode Twitter - @jhagglund
  2. Where are we going? • Why bother with UI test

    automation? • XCTest API and UI Elements • Identifying UI Elements (Storyboard and Programmatically) • Stop Relying on the Recorder and Automate Predictively • Write Better UI Automation Code with Screen Objects • Extras • Questions 2
  3. Why bother with UI test automation? Because this talk would

    be really lame if UI tests weren’t important or useful.
  4. The iOS UI and the XCTest API Looking at the

    structure of what we’re testing and the code that gives us the access to the UI.
  5. Our Toolbox for iOS UI Automation • XCode 7+ •

    XCTest (supports UI testing as of XCode 7, iOS 9+) • Swift 7
  6. • On the web: http://masilotti.com/xctest- documentation/index.html • Build it locally:

    https://github. com/joemasilotti/XCTest-Documentation Regarding XCTest Documentation... 8
  7. What is XCTest? 9 A build target that targets your

    application’s build target. Say that 10x fast.
  8. Your XCTest Bread and Butter • XCUIApplication ◦ This class

    models the application itself and has two functions: launch and terminate. • XCUIElement ◦ This class models a UI element contained within the application. • XCUIElementQuery ◦ This class models a search for an element. 10
  9. Identify UI Elements from the Storyboard The least painful way

    to uniquely tag our UI elements for automation purposes
  10. Accessibility Identifier > Accessibility Label 14 • Lest we forget:

    the primary purpose of Accessibility- enabled elements is to allow your app to be used in accessibility mode on the device. • Accessibility Labels are what the end user would actually see/hear in order to interact with your app. • Accessibility Identifiers don’t leave a mark.
  11. About Those Pesky Dynamically Generated Elements... • Protocol (similar to

    an Interface in Java): a collection of properties, methods, etc., that encapsulate common behavior that you want otherwise unrelated classes to share. • UIKit elements conform to the UIAccessibilityIdentification protocol, which has exactly one contract requirement: accessibilityIdentifier. 17
  12. Stop Recording and Write Predictive UI Tests The recorder is

    an exploration tool, not a testing tool.
  13. No Really, It’s This Easy (In Many Cases) var someButton

    = app.buttons[“accessibilityIdentifier”] “app” = instance of XCUIApplication “buttons” = just one of many XCUIElementTypeQueryProvider methods (hey look, another Protocol!) “accessibilityIdentifier” = the accessibility identifier you have configured for that element 21
  14. Why This Matters • Kill more bugs faster! (enables TDD-like

    practices) • Plus, just looks cleaner. Remember that ugly recorder-generated code earlier? 22
  15. Asynchronous Test Expectations • Doable, but kinda ugly. DRY and

    write methods that wait on elements once. • https://gist.github. com/kcharwood/0a57d7a207aba1d578da • http://masilotti.com/xctest-helpers/ 33
  16. Cucumber/Gherkin Goodness! • Yes, really, somebody is finally doing this!

    • Integrates with both KIF and XCTest • https://github.com/Ahmed-Ali/Cucumberish 35
  17. Scalable and Collaborative • Scalable: leverages the well-worn patterns and

    practices of object-oriented programming to make producing UI tests as easy and DRY as possible. • Collaborative: a first class citizen that lives in the application code and conforms to the same high-quality standards. • Devs + Testers can make awesome apps together 37