31
UI TESTING WITH EARL GREY SHYAM BHAT swift.berlin

UI Testing with Earl Grey

Embed Size (px)

Citation preview

Page 1: UI Testing with Earl Grey

UI TESTING WITH EARL GREY

SHYAM BHAT

swift.berlin

Page 2: UI Testing with Earl Grey

TESTING MOBILE APPS

Page 3: UI Testing with Earl Grey

APPS ARE GETTING COMPLEX

Page 4: UI Testing with Earl Grey

TESTING IS ESSENTIAL FOR GREAT QUALITY

Page 5: UI Testing with Earl Grey

TESTING INFLUENCES GOOD ARCHITECTURE

Page 6: UI Testing with Earl Grey

TESTING IMPROVES CODE READABILITY

Page 7: UI Testing with Earl Grey

PROGRAMS MUST BE WRITTEN FOR PEOPLE TO READ, AND ONLY INCIDENTALLY FOR MACHINES TO EXECUTE.

Harold Abelson

Page 8: UI Testing with Earl Grey

UI TESTS ARE ESSENTIAL

Page 9: UI Testing with Earl Grey

▸ Germany’s leading digital real estate marketplace.

▸ Over 12 million App downloads.

▸ Swift + Objective C

Page 10: UI Testing with Earl Grey

OUR TEST SUITE

▸ XCTest + FBSnapshots for Unit testing

▸ Xcode UI Testing + KIF

▸ 3000+ Unit tests and Integration tests.

Page 11: UI Testing with Earl Grey

BUT…

Page 12: UI Testing with Earl Grey

UI TESTS ARE SLOW AND COMPLEX TO WRITE

Page 13: UI Testing with Earl Grey

SYNCHRONIZING THE UI IS A PAIN

Page 14: UI Testing with Earl Grey

RESULTS ARE INCONSISTENT AND UNRELIABLE

Page 15: UI Testing with Earl Grey
Page 16: UI Testing with Earl Grey

MEET EARL GREY

Page 17: UI Testing with Earl Grey

EARL GREY IS AN UI AUTOMATION TEST FRAMEWORK THAT ENABLES

YOU TO WRITE CLEAR, CONCISE TESTS.

Page 18: UI Testing with Earl Grey

EARL GREY

▸ Google’s internal UI Testing framework.

▸ Used in YouTube, Google Calendar, Google Photos, Google Translate, Google Play Music.

▸ Recently open sourced.

Page 19: UI Testing with Earl Grey

FEATURES

▸ Synchronization.

▸ User-like interactions (taps, swipes).

▸ Visibility checks before interactions.

▸ Extensible API - custom UI actions and assertions.

Page 20: UI Testing with Earl Grey

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.

Page 21: UI Testing with Earl Grey

EARL GREY API

▸ Interaction APIs

▸ Synchronization APIs

▸ Other Top Level APIs

Page 22: UI Testing with Earl Grey

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.

Page 23: UI Testing with Earl Grey

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"))

Page 24: UI Testing with Earl Grey

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)

Page 25: UI Testing with Earl Grey

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())

Page 26: UI Testing with Earl Grey

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())

Page 27: UI Testing with Earl Grey

SEARCH FUNNEL TESTSDEMO :

Page 28: UI Testing with Earl Grey

OTHER API

▸ Custom Assertions and Matchers

▸ Failure Handlers

▸ Synchronization API

▸ Layout Testing

Page 29: UI Testing with Earl Grey

KNOWN ISSUES

▸ Cannot interact with system dialogs (yet).

▸ No 3D Touch support.

Page 30: UI Testing with Earl Grey

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

Page 31: UI Testing with Earl Grey

THANKS! QUESTIONS?

@bhatthead

github.com/shyambhat