android ui testing with uiautomator
DESCRIPTION
This presentation is about Android UI Testing with uiautomator library. Demo test available on github: https://github.com/Janamou/android-ui-testTRANSCRIPT
![Page 1: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/1.jpg)
Android UI Testingwith uiautomator
Jana Moudrá | @Janamou | +JanaMoudrá
![Page 2: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/2.jpg)
Me
Co-Founder at JuicymoGDG ČVUT Prague/GDG Prague
Web, Android, Design, Dart
about.me/janamou
![Page 3: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/3.jpg)
Motivation
![Page 4: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/4.jpg)
UI Testing
UI testing ensures that your application returns the correct UI output in response to a sequence
of user actions on a device.
http://developer.android.com/tools/testing/testing_ui.html
![Page 5: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/5.jpg)
UI Testing
No knowledge of implementation
Testing and implementation
separated
![Page 6: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/6.jpg)
Manual?
Time consumingNot repeatable
Error prone
![Page 7: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/7.jpg)
Manual?
Time consumingNot repeatable
Error prone
We want to automate
![Page 8: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/8.jpg)
Android?
![Page 9: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/9.jpg)
Android?uiautomator
![Page 10: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/10.jpg)
Android 4.1
Device
Tests in Java
![Page 11: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/11.jpg)
How to test
in 3 steps
![Page 12: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/12.jpg)
Create the App
1
![Page 13: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/13.jpg)
Prepare the Test
2
![Page 14: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/14.jpg)
Prepare the Test
Application is accessible
Application is on the device
Use uiautomatorviewer
Set development environment
Create the test
![Page 15: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/15.jpg)
Development environment
Java project
+JUnit + uiautomator.jar + android.jar
![Page 16: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/16.jpg)
Use uiautomatorviewer
![Page 17: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/17.jpg)
Create the Test
extend the
UiAutomatorTestCase class
![Page 18: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/18.jpg)
Use available classes
UiDeviceUiSelectorUiObject
UiCollectionUiScrollable
![Page 19: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/19.jpg)
UiSelector
UiObject threeButton = new UiObject(
new UiSelector().text("3"));
threeButton.click();
![Page 20: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/20.jpg)
UiSelector
UiObject urlForm = new UiObject(
new UiSelector()
.resourceId("com.android.browser:id/url"));
urlForm.setText("http://www.gug.cz");
getUiDevice().pressEnter();
![Page 21: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/21.jpg)
What can I do with UiObject?
Use gesturesRetrieve attributes
Set textNo manipulation
![Page 22: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/22.jpg)
We can use Asserts
assertEquals(threeButton.getText(), "3");
![Page 23: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/23.jpg)
Run the Test
3
![Page 24: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/24.jpg)
Run the Test
1) Build with Ant2) Push to device
3) Run the test
![Page 25: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/25.jpg)
DEMO
![Page 26: Android UI Testing with uiautomator](https://reader034.vdocuments.mx/reader034/viewer/2022052301/556442f5d8b42a9f128b4950/html5/thumbnails/26.jpg)
Thank You!Questions???
about.me/janamou