Android UI Testing with Appium
This presentation covers:
- how appium works
- setting up test development environment with AndroidStudio
- running tests
- UI automation best practices
- common problems with automation
2. Introduction : Luke Maung
Background in mobile / automation
● wrote mobile browser automation system for feature-
phones (Palmsource, 2004+)
● wrote distributed browser UI automation system with
Selenium/WebDriver (Yahoo! 2008+)
● Continuous Integration software engineer (LinkedIn,
2010+)
● Advise automation strategy to start-ups (2011+)
3. Introduction : Android Automation
● Concepts
● Setup that you can replicate easily
● Common automation use cases
4. UI Automation Tools - Maturity
Created Latest
Version
Sponsor Committers Commits Automation
Language
Robotium 2010 5.3.1 Google 33 1121 Java
Calabash 2013 0.5.8 Xamarin 56 1361 Ruby
Appium 2013 1.3.1 Saucelabs 139 5423 Multiple
Espresso 2013 2.0 Google 40+ ? Java
6. Appium : Benefits
1. Tests unmodified App
2. Works well on device and emulator
3. Uses well-defined WebDriver protocol
○ WebDriver is de facto standard for UI automation
○ extensive documentation
4. Good balance of low-level features and abstraction
○ can use any test framework (junit, testng, etc)
○ does not force specific test framework (eg calabash implies cucumber
framework)
5. Saucelabs very actively supports Appium
8. Architecture : Logical View
test runner
test script
webdriver
node server
appium.js
uiautomator
Bootstrap
Android
App
:4723 :4724
Test Driver Appium Server App Under Test
adb.js
adb
9. Setup: Install Tools
Gradle @ http://www.eng.lsu.edu/mirrors/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.zip
● GRADLE_HOME=E:gradle
● Add %GRADLE_HOME%bin to PATH
ADT @ https://developer.android.com/sdk/installing/index.html
● ANDROID_HOME = E:UserslukemaungAppDataLocalAndroidsdk
● Add %ANDROID_HOME%bin to PATH
● Create and save an emulator image, eg “android”
Appium Server
● node.js : http://nodejs.org/download/
● appium : npm install -g appium
● appium --device-name <device id> --avd <avd name> --address <ip> --port <port>
22. Test Script : Asserting Outcome
Common queries:
● e1.isDisplayed()
● e1.getText()
take screenshots
● File image = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
junit/testng asserts
● Assert.assertEquals(e1.getText(), “welcome”);
23. Common Pitfalls and Solutions
3 major classes of problems that break tests
1. Timing issues
○ write help methods to wrap findElementBy() with robust
wait/retry/FluentWait
○ do not use sleep. Performance variance is high
2. Many opportunities to fail from client to App
○ use full-reset launch option on Appium
○ kill adb between tests
3. Slow emulator
○ http://www.genymotion.com/
○ Use real device
24. Summary
You now know:
● A popular automation tool
● How it works
● How to set it up
● Typical test code
Next Step: Try it out! Ask questions!