Groovy Mobile Automation

Preview:

DESCRIPTION

In this talk, we will discuss mobile automation and dive into the iOS and Android functional testing world using Groovy, Spock and Gradle.

Citation preview

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Groovy Mobile AutomationBy Bobby Warner

Who Am I

Bobby Warner Founder & President

!!

@bobbywarner2

What is the objective?

• Functional test-cases written in Groovy & Spock that validate business functionality !

• Test-case suite that runs on multiple devices and platforms using Gradle !

• Automated execution of functional test-case suite

3

Appium Automation Library

4

What is Appium?

• Appium is an open source test automation framework for use with native and hybrid mobile apps. !

• It drives iOS and Android apps using the WebDriver JSON wire protocol. !

• Links: • http://appium.io • http://github.com/appium/appium

5

Appium Philosophy

1. You shouldn’t have to recompile your app or modify it in any way in order to automate it.

2. You shouldn’t be locked into a specific language or framework to write and run your tests.

3. A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs.

4. A mobile automation framework should be open source, in spirit and practice as well as in name!

6

#1

• You shouldn’t have to recompile your app or modify it in any way in order to automate it. !• Use vendor provided automation frameworks like

UIAutomation on iOS and UiAutomator on Android

7

#2

• You shouldn’t be locked into a specific language or framework to write and run your tests. !• Wrap the vendor-provided frameworks in a common API

known as the WebDriver API !

• WebDriver provides a client-server protocol called JSON wire-protocol

8

#3

• A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs.

!• WebDriver has become the de facto standard for automating

web browsers !

• WebDriver is a W3C Working Draft. !

• Appium extends the protocol with extra API methods useful for mobile automation.

9

#4

• A mobile automation framework should be open source, in spirit and practice as well as in name! !• Many commercial automation tools are overhyped and they

constantly under deliver !

• Avoid vendor lock-in and expensive contracts

10

What are the alternatives?

11

Architecture

12

What does it look like?

13

Appium Java Client

• Simple wrapper of Selenium 2.x !

• Uses GSON (Google’s JSON library) for communicating with Appium REST end-points !

• Conforms to Mobile JSON Wire Protocol !

• Provides all the usual Selenium features plus specific mobile actions • tap, swipe, pinch, zoom, shake, scrollTo, and many more!

14

Why use Groovy, Spock and Gradle?

• Groovy is very easy to learn for test engineers !

• Some test engineers already familiar with using Selenium with Java for traditional web automation

!• Spock helps keep these tests organized because they can get

out of control quickly !

• Gradle builds the test-suite and makes automating them very easy with a continuous integration server

15

Selenium 3 and Mobile?

• Still a work in progress, steadily moving forward, a big update will likely be required !

• Android and iPhone Selenium drivers deprecated in favor of other compatible libraries • Like Appium!

16

Demos

17

Demo Build File

18

Demo #1

• HelloSpec Demo • Test iOS and Android with separate tests

19

Demo #2

• HelloSpec Demo with Helpers • Test iOS and Android together with one test and helpers

20

Demo #3

• HelloSpec with Data • Test iOS and Android

together using Spock’s @Unroll

21

Demo #4

• LocaleSpec Demo • Data-Driven Spock testing to change the locale and language for device • DesiredCapabilities class currently only supports locale for iOS • Have to implement a workaround for Android for now

22

Demo #5

• AccountSpec Demo • Data-Driven Spock test for data entry to create an account • Tests blank passwords • Tests password confirmation field

23

Continuous Integration

24

Building the Apps

• Jenkins for Android and Test Suite • Best practice that has been used for years

!• XcodeBots for iOS

• Relatively new (last year’s WWDC with Xcode 5), but quickly becoming the defacto standard for continuous integration for iOS

!• Run both on a MacMini or MacPro (OSX required)

• Best practice is to setup one server for mobile continuous integration for both platforms that takes care of the usual iOS and Android publishing tasks like provisioning profiles, signing IPAs/APKs, etc.

25

Running the Tests

• Separate jobs for test suite platforms and locales to run in parallel • Platform = OS + Hardware !

• Number of Test Jobs Grows Very Quickly! • iOS + iPhone 5S + en_US • iOS + iPhone 5S + es_ES • iOS + iPhone 5S + fr_FR • iOS + iPad + en_US • iOS + iPad + es_ES • iOS + iPad + fr_FR • And now all the possible Android combinations!

26

Running the Tests

• iOS Simulators and Android Emulators • Limited • Simulator vs Emulator • Genymotion for Android

• Test devices plugged into the Mac • Test devices provided (i.e. Sauce Labs)

• Multiple platforms + multiple versions = 1000s of tests! • Run your tests on different device configurations as opposed to managing

your own test devices • Run tests in parallel (they take a long time to execute!)

27

Where to go from here?

28

Define a Testing Contract with Stakeholders

• What are the test configurations? • Android 2.3 still unbelievably has 13%, but don’t waste your time writing

automated tests for it. Focus on Android 4.0+ • Only worry about N and N-1 for iOS (today this is iOS 8 and iOS 7) !

• What is the goal for automated tests? • % of function points • % of user stories • % of test cases currently being run by QA

29

Establish a Mobile Testing Strategy

• What can you rely on? • APIs you trust • APIs you can’t trust

!• What takes the most time testing your app today?

• Manual input of any data • Language based testing

!• How to find the right balance of mobile testing?

• The time it takes to maintain the test compared to the value they provide

30

Establish a Mobile Testing Strategy

• Decoupling Components • Using a mobile test-suite to test back-end systems will not scale • Focus on testing each component separately

!• Automation Investment Pays for Itself

• 50 generalized test cases in 3 locales across 7 platforms = 1,050 tests • QA Teams don’t always do regression testing and this is the most valuable

aspect of automation testing (new feature didn’t break existing functionality) • Automation allows us to run all regression tests daily!

31

Call To Action

• Write one functional test-case written in Groovy & Spock that validates some business functionality of your company’s mobile app • iOS or Android, but preferably both!

!• Show it to your QA department

• Most likely they will be very resistant at first because it’s completely foreign • Once they see the time that can be saved though, they’ll be hooked

32

Q & A

33

!Thank you for attending this talk!

!Thank you SpringOne2GX organizers and sponsors!

Recommended