SlideShare a Scribd company logo
Android UI Testing
Luke Maung, 2015
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+)
Introduction : Android Automation
● Concepts
● Setup that you can replicate easily
● Common automation use cases
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
UI Automation Tools - Popularity
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
Architecture : Physical View
Test Driver Appium Server App Under Test
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
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>
Sample Test Development
Environment
TEST DEVELOPMENT
APPIUM SERVER
EMULATOR
(RUNS APP UNDER TEST)
Setup Test Development Environment
1. create dir app/src/test/java
2. create test.gradle build config
3. add SwipeableWebDriver
4. add sample test script
Create Test Script Build Configuration
test.gradle:
apply plugin: 'java'
repositories {
mavenCentral()
}
ext.seleniumVersion = '2.45.0'
sourceSets {
main {
java {
srcDir 'src/java/'
exclude '**/**'
}
}
}
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:seleniumVersion
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Create Android Driver
import java.net.URL;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.interactions.*;
import org.openqa.selenium.remote.*;
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
private RemoteTouchScreen touch;
public SwipeableWebDriver() { }
public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
touch = new RemoteTouchScreen(getExecuteMethod());
}
public TouchScreen getTouch() {
return touch;
}
}
Test Script Part 1: Setup Appium Session
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", "<path-to-apk>");
WebDriver driver = new SwipeableWebDriver(
new URL("http://<host-name>:4723/wd/hub"), capabilities);
Test Script Part 2: Perform Navigation
1. Get a reference to the element:
○ WebElement e1 = driver.findElementBy.id, <id>)
○ WebElement e2 = driver.findElement(By.name, <content-desc>)
○ WebElement e3 = driver.findElement(By.xpath, <xpath>)
2. Invoke UI operation:
○ e1.click()
○ e2.sendKeys(“john doe”)
Test Script: Complete
public class AndroidTest extends TestCase {
public void testSomething() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", "E:/Dev/workspace/ApiDemos.apk");
WebDriver driver = new SwipeableWebDriver(
new URL("http://localhost:4723/wd/hub"), capabilities);
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@text='Animation']")).click();
driver.findElement(By.xpath("//*[@text='Cloning']")).click();
WebElement runButton = driver.findElement(By.xpath("//*[@text='Run']"));
assertTrue(runButton.isDisplayed());
runButton.click();
}
}
Run Tests
1. Launch Appium:
○ appium --avd android --session-override --log-level info
2. Run Tests:
○ gradle -b test.gradle cleanTest test
App
Android
uiautomator
Bootstrap
adb
adb.js
appium.jswebdriver
test script
test runner
What Just Happened?
node server
:4724
Test Launcher Appium Server App Under Test
1) copy bootstrap.jar
3) run
uiautomator
2) install app and launch
:4723start-session()
Advanced Navigation: Gestures
Initialize touch action:
● TouchActions touchScreen = new TouchActions(driver)
Common gestures:
● touchScreen.flick(10, 0).perform() // swipe right
● touchScreen.flick(0, -10).perform() // swipe up
● touchScreen.doubleTap(elem).perform() // double tap
Locating Elements: ADT monitor
cd c:adtsdktools
monitor
click Dump View
Hiearchy button
Locating Elements: Techniques
1. Resource-id: By.id()
○ eg: By.id(“com.company.appName:id/ButtonSignIn”)
2. content-desc: By.name()
○ eg: By.name(“Downloads”)
3. Fallback: By.xpath()
○ eg: By.xpath("//*[@text='Animation']")
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”);
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
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!
Q&A

More Related Content

PDF
Appium & Jenkins
PPTX
Parallel Test Runs with Appium on Real Mobile Devices – Hands-on Webinar
PDF
Appium Mobile Test Automation like WebDriver
PDF
Getting started with appium
PPTX
Appium solution
PDF
Appium workshop technopark trivandrum
PPTX
Automation testing on ios platform using appium
PDF
What's New With Appium? From 1.0 to Now
Appium & Jenkins
Parallel Test Runs with Appium on Real Mobile Devices – Hands-on Webinar
Appium Mobile Test Automation like WebDriver
Getting started with appium
Appium solution
Appium workshop technopark trivandrum
Automation testing on ios platform using appium
What's New With Appium? From 1.0 to Now

What's hot (20)

PPTX
Appium overview
PPTX
Cross Platform Appium Tests: How To
PDF
Appium basics
PDF
Automated UI Testing Frameworks
PPT
PPT
Using Selenium to Test Native Apps (Wait, you can do that?)
PPT
Android & iOS Automation Using Appium
PDF
Testing Native iOS Apps with Appium
PPTX
Mobile Automation with Appium
PPT
PDF
Appium@Work at PAYBACK
PDF
Future of Mobile Automation, Appium Steals it
PPTX
Automation Testing With Appium
PDF
Mobile Test Automation - Appium
PDF
Selenium, Appium, and Robots!
PPTX
Wheat - Mobile functional test automation
PPTX
Appium meet up noida
PPTX
Do You Enjoy Espresso in Android App Testing?
PDF
Mobile automation – should I use robotium or calabash or appium?
PPTX
Parallel testing with appium
Appium overview
Cross Platform Appium Tests: How To
Appium basics
Automated UI Testing Frameworks
Using Selenium to Test Native Apps (Wait, you can do that?)
Android & iOS Automation Using Appium
Testing Native iOS Apps with Appium
Mobile Automation with Appium
Appium@Work at PAYBACK
Future of Mobile Automation, Appium Steals it
Automation Testing With Appium
Mobile Test Automation - Appium
Selenium, Appium, and Robots!
Wheat - Mobile functional test automation
Appium meet up noida
Do You Enjoy Espresso in Android App Testing?
Mobile automation – should I use robotium or calabash or appium?
Parallel testing with appium
Ad

Viewers also liked (20)

PDF
모바일 게임 테스트 자동화 (Appium 확장)
PDF
Appium: Automation for Mobile Apps
PPTX
Getting Started with Mobile Test Automation & Appium
PPTX
Android Automation Testing with Selendroid
PDF
테스트자동화 성공전략
PDF
Ui test 자동화하기 - Selenium + Jenkins
PDF
Tech Talk #5 : KIF-iOS Integration Testing Framework - Nguyễn Hiệp
PDF
Automated UI testing for iOS apps using KIF framework and Swift
PPSX
Cross platform test automation using Appium
PDF
iOS Testing With Appium at Gilt
PDF
Appium
PPTX
Appium - test automation for mobile apps
PDF
Appium: Mobile Automation Made Awesome
PPT
Android automation tools
PPTX
Best Practices in Mobile CI (webinar)
PPTX
Testing Your Android and iOS Apps with Appium in Testdroid Cloud
PPTX
Mob Testing
PDF
iOS and Android Acceptance Testing with Calabash - Xcake Dublin
PDF
TestWorksConf: Exploratory Testing an API in Mob
PDF
모바일 앱(App) 개발 테스트 솔루션 v20160415
모바일 게임 테스트 자동화 (Appium 확장)
Appium: Automation for Mobile Apps
Getting Started with Mobile Test Automation & Appium
Android Automation Testing with Selendroid
테스트자동화 성공전략
Ui test 자동화하기 - Selenium + Jenkins
Tech Talk #5 : KIF-iOS Integration Testing Framework - Nguyễn Hiệp
Automated UI testing for iOS apps using KIF framework and Swift
Cross platform test automation using Appium
iOS Testing With Appium at Gilt
Appium
Appium - test automation for mobile apps
Appium: Mobile Automation Made Awesome
Android automation tools
Best Practices in Mobile CI (webinar)
Testing Your Android and iOS Apps with Appium in Testdroid Cloud
Mob Testing
iOS and Android Acceptance Testing with Calabash - Xcake Dublin
TestWorksConf: Exploratory Testing an API in Mob
모바일 앱(App) 개발 테스트 솔루션 v20160415
Ad

Similar to Android UI Testing with Appium (20)

PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
PPTX
Using protractor to build automated ui tests
PPTX
Protractor framework architecture with example
PPTX
Selenium
PDF
Good practices for debugging Selenium and Appium tests
PDF
Browser_Stack_Intro
PPTX
OWASP ZAP Workshop for QA Testers
PDF
探討Web ui自動化測試工具
PPTX
Selenium.pptx
PDF
End to-end testing from rookie to pro
PDF
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
PPTX
MDC2011 Android_ Webdriver Automation Test
PDF
Selenium Full Material( apprendre Selenium).pdf
PPTX
Setting Apple's UI Automation Free with Appium
PDF
Introduction to Selenium and WebDriver
PPTX
test_automation_POC
PPTX
Protractor Testing Automation Tool Framework / Jasmine Reporters
ODP
eXo Platform SEA - Play Framework Introduction
PPT
Pragmatic Parallels: Java and JavaScript
PPTX
Automated Smoke Tests with Protractor
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
Using protractor to build automated ui tests
Protractor framework architecture with example
Selenium
Good practices for debugging Selenium and Appium tests
Browser_Stack_Intro
OWASP ZAP Workshop for QA Testers
探討Web ui自動化測試工具
Selenium.pptx
End to-end testing from rookie to pro
Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter
MDC2011 Android_ Webdriver Automation Test
Selenium Full Material( apprendre Selenium).pdf
Setting Apple's UI Automation Free with Appium
Introduction to Selenium and WebDriver
test_automation_POC
Protractor Testing Automation Tool Framework / Jasmine Reporters
eXo Platform SEA - Play Framework Introduction
Pragmatic Parallels: Java and JavaScript
Automated Smoke Tests with Protractor

Recently uploaded (6)

PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
PDF
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
PPTX
ASMS Telecommunication company Profile
PDF
heheheueueyeyeyegehehehhehshMedia-Literacy.pdf
DOC
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
DOC
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
ASMS Telecommunication company Profile
heheheueueyeyeyegehehehhehshMedia-Literacy.pdf
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证

Android UI Testing with Appium

  • 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
  • 5. UI Automation Tools - Popularity
  • 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
  • 7. Architecture : Physical View Test Driver Appium Server App Under Test
  • 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>
  • 10. Sample Test Development Environment TEST DEVELOPMENT APPIUM SERVER EMULATOR (RUNS APP UNDER TEST)
  • 11. Setup Test Development Environment 1. create dir app/src/test/java 2. create test.gradle build config 3. add SwipeableWebDriver 4. add sample test script
  • 12. Create Test Script Build Configuration test.gradle: apply plugin: 'java' repositories { mavenCentral() } ext.seleniumVersion = '2.45.0' sourceSets { main { java { srcDir 'src/java/' exclude '**/**' } } } dependencies { compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:seleniumVersion testCompile group: 'junit', name: 'junit', version: '4.+' }
  • 13. Create Android Driver import java.net.URL; import org.openqa.selenium.Capabilities; import org.openqa.selenium.interactions.*; import org.openqa.selenium.remote.*; public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen { private RemoteTouchScreen touch; public SwipeableWebDriver() { } public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) { super(remoteAddress, desiredCapabilities); touch = new RemoteTouchScreen(getExecuteMethod()); } public TouchScreen getTouch() { return touch; } }
  • 14. Test Script Part 1: Setup Appium Session DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName","Android Emulator"); capabilities.setCapability("platformName","Android"); capabilities.setCapability("app", "<path-to-apk>"); WebDriver driver = new SwipeableWebDriver( new URL("http://<host-name>:4723/wd/hub"), capabilities);
  • 15. Test Script Part 2: Perform Navigation 1. Get a reference to the element: ○ WebElement e1 = driver.findElementBy.id, <id>) ○ WebElement e2 = driver.findElement(By.name, <content-desc>) ○ WebElement e3 = driver.findElement(By.xpath, <xpath>) 2. Invoke UI operation: ○ e1.click() ○ e2.sendKeys(“john doe”)
  • 16. Test Script: Complete public class AndroidTest extends TestCase { public void testSomething() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName","Android Emulator"); capabilities.setCapability("platformName","Android"); capabilities.setCapability("app", "E:/Dev/workspace/ApiDemos.apk"); WebDriver driver = new SwipeableWebDriver( new URL("http://localhost:4723/wd/hub"), capabilities); Thread.sleep(5000); driver.findElement(By.xpath("//*[@text='Animation']")).click(); driver.findElement(By.xpath("//*[@text='Cloning']")).click(); WebElement runButton = driver.findElement(By.xpath("//*[@text='Run']")); assertTrue(runButton.isDisplayed()); runButton.click(); } }
  • 17. Run Tests 1. Launch Appium: ○ appium --avd android --session-override --log-level info 2. Run Tests: ○ gradle -b test.gradle cleanTest test
  • 18. App Android uiautomator Bootstrap adb adb.js appium.jswebdriver test script test runner What Just Happened? node server :4724 Test Launcher Appium Server App Under Test 1) copy bootstrap.jar 3) run uiautomator 2) install app and launch :4723start-session()
  • 19. Advanced Navigation: Gestures Initialize touch action: ● TouchActions touchScreen = new TouchActions(driver) Common gestures: ● touchScreen.flick(10, 0).perform() // swipe right ● touchScreen.flick(0, -10).perform() // swipe up ● touchScreen.doubleTap(elem).perform() // double tap
  • 20. Locating Elements: ADT monitor cd c:adtsdktools monitor click Dump View Hiearchy button
  • 21. Locating Elements: Techniques 1. Resource-id: By.id() ○ eg: By.id(“com.company.appName:id/ButtonSignIn”) 2. content-desc: By.name() ○ eg: By.name(“Downloads”) 3. Fallback: By.xpath() ○ eg: By.xpath("//*[@text='Animation']")
  • 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!
  • 25. Q&A