UI Testing with Earl Grey

Post on 08-Feb-2017

946 views 0 download

Transcript of UI Testing with Earl Grey

UI TESTING WITH EARL GREY

SHYAM BHAT

swift.berlin

TESTING MOBILE APPS

APPS ARE GETTING COMPLEX

TESTING IS ESSENTIAL FOR GREAT QUALITY

TESTING INFLUENCES GOOD ARCHITECTURE

TESTING IMPROVES CODE READABILITY

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

Harold Abelson

UI TESTS ARE ESSENTIAL

▸ Germany’s leading digital real estate marketplace.

▸ Over 12 million App downloads.

▸ Swift + Objective C

OUR TEST SUITE

▸ XCTest + FBSnapshots for Unit testing

▸ Xcode UI Testing + KIF

▸ 3000+ Unit tests and Integration tests.

BUT…

UI TESTS ARE SLOW AND COMPLEX TO WRITE

SYNCHRONIZING THE UI IS A PAIN

RESULTS ARE INCONSISTENT AND UNRELIABLE

MEET EARL GREY

EARL GREY IS AN UI AUTOMATION TEST FRAMEWORK THAT ENABLES

YOU TO WRITE CLEAR, CONCISE TESTS.

EARL GREY

▸ Google’s internal UI Testing framework.

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

▸ Recently open sourced.

FEATURES

▸ Synchronization.

▸ User-like interactions (taps, swipes).

▸ Visibility checks before interactions.

▸ Extensible API - custom UI actions and assertions.

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.

EARL GREY API

▸ Interaction APIs

▸ Synchronization APIs

▸ Other Top Level APIs

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.

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

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)

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

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

SEARCH FUNNEL TESTSDEMO :

OTHER API

▸ Custom Assertions and Matchers

▸ Failure Handlers

▸ Synchronization API

▸ Layout Testing

KNOWN ISSUES

▸ Cannot interact with system dialogs (yet).

▸ No 3D Touch support.

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

THANKS! QUESTIONS?

@bhatthead

github.com/shyambhat