Slide 1

Slide 1 text

Building the automated Android UI testing in Continuous Integration Somkiat Khitwongwattana Android GDE @akexorcist At LINE MAN Wongnai

Slide 2

Slide 2 text

LINE MAN Wongnai LINE MAN Rider LINE MAN Driver Wongnai Merchant Wongnai POS Consumer Local Business Rider & Driver Wongnai POS Manager

Slide 3

Slide 3 text

LINE MAN Wongnai LINE MAN Rider LINE MAN Driver Wongnai Merchant Wongnai POS React Native Native Android (Kotlin) Wongnai POS Manager

Slide 4

Slide 4 text

Running Android UI testing in continuous integration is challenging for developers, but it's necessary for future scalability of Android apps.

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Our previous infrastructure Which isn’t good enough for current requirements ● Not scalable ● Not maintainable ● Unstable 🥲 😢 😭

Slide 7

Slide 7 text

Native Android React Native Marathon Detox Allure Jest Yes No UI Testing Integration End-to-end Test Reporting Yes Yes Test Executor Continuous Integration GitLab GitLab

Slide 8

Slide 8 text

Android Device Provider Marathon Detox Allure Jest Yes No UI Testing Integration End-to-end Test Reporting Yes Yes Test Executor tinuous gration tLab tLab

Slide 9

Slide 9 text

Candidates Smartphone Test Farm Genymotion Device Image Firebase Test Lab

Slide 10

Slide 10 text

Firebase Test Lab Key Features ● Test both Android and iOS apps ● Real and virtual devices ● Google Play Service included ● Wide range of supported devices ● Test matrix execution is supported Note: Test reports are stored on Google Cloud Storage https://firebase.google.com/products/test-lab

Slide 11

Slide 11 text

Firebase Test Lab Pricing Virtual device ● No-cost up to 60 min / day ● Then $1 / device / hour Physical device ● No-cost up to 30 min / day ● Then $5 / device / hour

Slide 12

Slide 12 text

Genymotion Device Image Key Features ● Available on well-known cloud service providers ● Virtual devices without GPU ● Remotely control via web browser and HTTP API ● Run app for ARM natively with ARM64 instances ● Provide SSH and ADB access https://www.genymotion.com

Slide 13

Slide 13 text

Genymotion Device Image Pricing Depending on the instance size t4g.medium ● 2 vCPU ● 4GB of memory ● $0.295 / hr c6g.xlarge ● 4 vCPU ● 8GB of memory ● $0.636 / hr

Slide 14

Slide 14 text

Smartphone Test Farm Key Features ● Open-source project ● Remote control any device from your browser ● Monitor your device inventory ● Reserve and release any device with STF API https://github.com/DeviceFarmer/stf

Slide 15

Slide 15 text

Price Maintainability Custom Test Executor VPN Stability Configurability Ease of use

Slide 16

Slide 16 text

Price Ease of use C ustom Test Executor VPN Stability M aintainability C onfigurability Firebase Test Lab Genymotion Device Image Smartphone Test Farm

Slide 17

Slide 17 text

Swollen battery problem on a physical device

Slide 18

Slide 18 text

Build App APK & Test APK Run UI Test Generate Test Report

Slide 19

Slide 19 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance

Slide 20

Slide 20 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance

Slide 21

Slide 21 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Terraform

Slide 22

Slide 22 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Connect ADB Shell Script

Slide 23

Slide 23 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Install APKs & Run UI test Collect test result & device log

Slide 24

Slide 24 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Terraform

Slide 25

Slide 25 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance

Slide 26

Slide 26 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance

Slide 27

Slide 27 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Cron Job Destroy instance

Slide 28

Slide 28 text

Run UI Test GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Terraform

Slide 29

Slide 29 text

AMI AWS VPC ● AMI: Amazon Machine Image ● VPC: Virtual Private Cloud Subscribe Launch Genymotion Instance

Slide 30

Slide 30 text

Original Genymotion AMI ● ADB disabled by default ● No Google Mobile Services ● Undesired screen size ● No WebView engine ● English language by default

Slide 31

Slide 31 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB

Slide 32

Slide 32 text

Genymotion HTTP API ● ADB ● Clipboard ● Screen resolution ● Screen orientation ● Download, upload, or delete file ● Send key, mouse, or tap event ● Screenshot ● Battery ● GPS ● And more

Slide 33

Slide 33 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB POST /api/v1/configure/adb { "active": true, "active_on_reboot": true }

Slide 34

Slide 34 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb connect

Slide 35

Slide 35 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB POST /api/v1/android/resolution { "width": 720, "height": 1440, "dpi": 300 }

Slide 36

Slide 36 text

Screen resolution configuration Mobile Tablet ● 720 x 1,440 px ● 384 x 768 dp ● 300 DPI ● 1,335 x 751 px ● 1,335 x 751 dp ● 160 DPI

Slide 37

Slide 37 text

Screen resolution configuration Mobile Tablet ● 720 x 1,440 px ● 384 x 768 dp ● 300 DPI ● 1,335 x 751 px ● 1,335 x 751 dp ● 160 DPI https://developer.android.com/reference/android/util/DisplayMetrics

Slide 38

Slide 38 text

Screen resolution configuration Mobile Tablet ● 720 x 1,440 px ● 384 x 768 dp ● 300 DPI ● 1,335 x 751 px ● 1,335 x 751 dp ● 160 DPI https://developer.android.com/reference/android/util/DisplayMetrics DP x (DPI / 160) = PX

Slide 39

Slide 39 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB POST /api/v1/sensors/gps { "latitude": 13.7223497, "longitude": 100.5804235, "altitude": 0, "accuracy": 10, "bearing": 0, "speed": 0 }

Slide 40

Slide 40 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell setprop persist.sys.local "th-TH"

Slide 41

Slide 41 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB

Slide 42

Slide 42 text

OpenGApps An open-source initiative that provides Google Apps package Pico package ● Google Play services https://opengapps.org

Slide 43

Slide 43 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell wget -O /sdcard/Download/opengapps.zip adb shell system/bin/flash-archive.sh /sdcard/Download/opengapps.zip

Slide 44

Slide 44 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell wget -O /sdcard/Download/chrome.zip adb shell pm install -r /sdcard/Download/chrome.apk adb shell wget -O /sdcard/Download/maps.zip adb shell pm install -r /sdcard/Download/maps.apk

Slide 45

Slide 45 text

Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps All setup operations HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb reboot adb disconnect

Slide 46

Slide 46 text

Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps All setup operations HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB

Slide 47

Slide 47 text

Allow Google’s Location Service Using a shell script and ADB to enable Google's Location Service from the Google Maps app

Slide 48

Slide 48 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell pm grant com.google.android.apps.maps \ android.permission.ACCESS_COARSE_LOCATION adb shell pm grant com.google.android.apps.maps \ android.permission.ACCESS_FINE_LOCATION

Slide 49

Slide 49 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell uiautomator dump adb pull /sdcard/window_dump.xml

Slide 50

Slide 50 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell uiautomator dump adb pull /sdcard/window_dump.xml

Slide 51

Slide 51 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell uiautomator dump adb pull /sdcard/window_dump.xml

Slide 52

Slide 52 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell uiautomator dump adb pull /sdcard/window_dump.xml

Slide 53

Slide 53 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB adb shell uiautomator dump adb pull /sdcard/window_dump.xml

Slide 54

Slide 54 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB PATTERN='string(//node[@text="SKIP"][1]/@bounds)' POSITION=$( xmllint --xpath $PATTERN window_dump.xml | awk -F '[\\[\\],]' '{printf("%d %d",($2+$5)/2,($3+$6)/2)}' ) adb shell input tab $POSITION

Slide 55

Slide 55 text

All setup operations Enable ADB connection Connect device Change screen resolution Change device location Change device language Install OpenGApps Install Google Maps and Chrome for Android Reboot the device Reconnect the ADB after device rebooted Grant location permission for Google Maps Allow Google’s Location Service from Google Maps HTTP ADB HTTP HTTP ADB ADB ADB ADB ADB ADB ADB PATTERN='string(//node[@text="SKIP"][1]/@bounds)' POSITION=$( xmllint --xpath $PATTERN window_dump.xml | awk -F '[\\[\\],]' '{printf("%d %d",($2+$5)/2,($3+$6)/2)}' ) adb shell input tab $POSITION

Slide 56

Slide 56 text

Allow Google’s Location Service ● Launch Google Maps app ● Tap on “SKIP” button ● Tap on current location button ● Tap on “OK” button ● Back to home screen ● Start the UI testing

Slide 57

Slide 57 text

AMI AWS VPC ● AMI: Amazon Machine Image ● VPC: Virtual Private Cloud Subscribe Launch Genymotion Instance Terraform

Slide 58

Slide 58 text

AMI AWS ● AMI: Amazon Machine Image ● VPC: Virtual Private Cloud Sub Launch VPC Genymotion Instance

Slide 59

Slide 59 text

AMI AWS ● AMI: Amazon Machine Image ● VPC: Virtual Private Cloud Sub Launch VPC Genymotion Instance Setup Custom AMI Snapshot

Slide 60

Slide 60 text

AMI AWS ● AMI: Amazon Machine Image ● VPC: Virtual Private Cloud Sub Launch VPC Genymotion Instance Setup Custom AMI Snapshot Packer

Slide 61

Slide 61 text

GitLab Runner Genymotion Device Image on AWS EC2 Start Job Create Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Terraform

Slide 62

Slide 62 text

GitLab Runner Genymotion Device Image on AWS EC2 Start Job Pre-configured Instance Initialization Test Execution End Job Test Execution Initialization Destroy Instance Terraform Custom AMI

Slide 63

Slide 63 text

Summary Now ● More scalable and stable CI system for Android UI testing ● Compatible with any mobile framework for Android app ● All of our Android apps have been successfully migrated to this new CI system ● Provide teams with a seamless opportunity to implement automated end-to-end testing ● Genymotion's monthly costs are highly cost-effective for our CI/CD system's results

Slide 64

Slide 64 text

Summary On the other side ● Genymotion charges by usage time. Optimizing UI testing to reduce the time spent will significantly reduce costs for the company. ● Working with a Site Reliability Engineer to create the system will take a few months, with additional months needed for improvements. ● Running Genymotion with public IP address will be vulnerable to bot script embedding by attackers.

Slide 65

Slide 65 text

Android Developer Site Reliability Engineer CI for Android UI Testing

Slide 66

Slide 66 text

Thank you Somkiat Khitwongwattana Android GDE @akexorcist