Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

UI Testing with Earl Grey

3,951 views

Published on

An introduction to Earl Grey - Google's powerful UI Automation Framework for native iOS Apps and a demo of its usage in the ImmobilienScout App.

Published in: Technology
  • Be the first to comment

UI Testing with Earl Grey

  1. 1. UI TESTING WITH EARL GREY SHYAM BHAT swift.berlin
  2. 2. TESTING MOBILE APPS
  3. 3. APPS ARE GETTING COMPLEX
  4. 4. TESTING IS ESSENTIAL FOR GREAT QUALITY
  5. 5. TESTING INFLUENCES GOOD ARCHITECTURE
  6. 6. TESTING IMPROVES CODE READABILITY
  7. 7. PROGRAMS MUST BE WRITTEN FOR PEOPLE TO READ, AND ONLY INCIDENTALLY FOR MACHINES TO EXECUTE. Harold Abelson
  8. 8. UI TESTS ARE ESSENTIAL
  9. 9. ▸ Germany’s leading digital real estate marketplace. ▸ Over 12 million App downloads. ▸ Swift + Objective C
  10. 10. OUR TEST SUITE ▸ XCTest + FBSnapshots for Unit testing ▸ Xcode UI Testing + KIF ▸ 3000+ Unit tests and Integration tests.
  11. 11. BUT…
  12. 12. UI TESTS ARE SLOW AND COMPLEX TO WRITE
  13. 13. SYNCHRONIZING THE UI IS A PAIN
  14. 14. RESULTS ARE INCONSISTENT AND UNRELIABLE
  15. 15. MEET EARL GREY
  16. 16. EARL GREY IS AN UI AUTOMATION TEST FRAMEWORK THAT ENABLES YOU TO WRITE CLEAR, CONCISE TESTS.
  17. 17. EARL GREY ▸ Google’s internal UI Testing framework. ▸ Used in YouTube, Google Calendar, Google Photos, Google Translate, Google Play Music. ▸ Recently open sourced.
  18. 18. FEATURES ▸ Synchronization. ▸ User-like interactions (taps, swipes). ▸ Visibility checks before interactions. ▸ Extensible API - custom UI actions and assertions.
  19. 19. HOW EARL GREY WORKS ▸ EarlGrey runs in the same process as the app under test, and has access to the same memory as the app. ▸ Uses private methods to learn view hierarchy and inject touches. ▸ Works in conjunction with the XCTest framework.
  20. 20. EARL GREY API ▸ Interaction APIs ▸ Synchronization APIs ▸ Other Top Level APIs
  21. 21. INTERACTION APIS ▸ Selection API - Selecting an element to interact with. ▸ Action API - Performing an action on it, ▸ Assertion API - Making an assertion to verify state and behavior.
  22. 22. SELECTION ▸ Format: selectElementWithMatcher(<GREYMatcher>) ▸ GREYMatcher grey_accessibilityID(“ClickMe”) grey_accessibilityLabel(“Berlin") grey_kindOfClass(UITableViewCell) ▸ Example: // Select the button with Accessibility ID "clickMe". EarlGrey().selectElementWithMatcher(grey_accessibilityID("ClickMe"))
  23. 23. SELECTION ▸ A GREYMatcher compliant object can be ambiguous and match multiple elements. ▸ Must be narrowed down until a single element is identified. ▸ You can combine multiple GREYMatchers using - grey_allOf() grey_anyOf() grey_not() ▸ Example: let sendButtonMatcher : <GREYMatcher> = grey_allOf(grey_accessibilityLabel("Send"), grey_sufficientlyVisible(), nil) EarlGrey().selectElementWithMatcher(sendButtonMatcher)
  24. 24. ACTION ▸ Format: selectElementWithMatcher(<GREYMatcher>).performAction(<GREYAction>) ▸ <GREYAction> grey_tap() grey_longPress() grey_tapAtPoint(CGPoint point) grey_scrollInDirection(GREYDirection direction, CGFloat amount) ▸ Example: // Select the button with Accessibility ID “clickMe" and perform Tap Action. EarlGrey().selectElementWithMatcher(grey_accessibilityID(“ClickMe”)). performAction(grey_tap())
  25. 25. ASSERTIONS ▸ Format: selectElementWithMatcher(<GREYMatcher>).assertWithMatcher(<GREYAction>) ▸ Example: // Select the button with Accessibility ID “ClickMe" and perform Tap Action. EarlGrey().selectElementWithMatcher(grey_accessibilityID(“ClickMe”)) .assertWithMatcher(grey_sufficientlyVisible())
  26. 26. SEARCH FUNNEL TESTS DEMO :
  27. 27. OTHER API ▸ Custom Assertions and Matchers ▸ Failure Handlers ▸ Synchronization API ▸ Layout Testing
  28. 28. KNOWN ISSUES ▸ Cannot interact with system dialogs (yet). ▸ No 3D Touch support.
  29. 29. REFERENCES ▸ Github Repository and API Documentation - https:// github.com/google/EarlGrey ▸ Google’s Developer blog - https:// developers.googleblog.com/2016/02/earlgrey-ios- functional-ui-testing.html
  30. 30. THANKS! QUESTIONS? @bhatthead github.com/shyambhat

×