Slide 1

Slide 1 text

Michael Aubert Android DevOps Espresso on Genymotion in AWS

Slide 2

Slide 2 text

Starling Bank 100% cloud based, Mobile only Personal & Business current accounts • Mastercard debit card • Direct debits • Faster Payments • Current Account Switching Service Card Control Spending Insights Savings Goals Public APIs, Marketplace

Slide 3

Slide 3 text

The automated QA system for our Android application CI system is in AWS cloud Genymotion-on-Demand provides Android in AWS. Push Code CI Trigger Run Tests Build APK Publish Results

Slide 4

Slide 4 text

On push to git: • Multiple Androids run tests in parallel: Sharding. • Keep all Logcat. • Record all screens into videos. • Extract JUnit test report. • Measure total code coverage. Quarterly: • Use new version of Genymotion-on-Demand

Slide 5

Slide 5 text

Scalable Maintained Supported Movable Influenceable Efficient Oracle HVX ✓ ✓ ✕ ✓ ✕ ✕ Amazon farm ✓ ✓ ✓ ✓ ✕ ✕ Firebase lab ✓ ✓ ✓ ✓ ✕ ✓ Dedicated ✕ ✕ ✕ ✕ ✓ ✕ Anbox.io ✓ ✕ ✕ ✓ ✓ ✓ Genymotion ✓ ✓ ✓ ✓ ✓ ✓ Why:

Slide 6

Slide 6 text

Why we built so much: AGPv3 broke Spoon for a while Starling engineering culture

Slide 7

Slide 7 text

How to automate Espresso: Push Code CI Trigger Run Tests Build APK Publish Results

Slide 8

Slide 8 text

Hot to run tests from Gradle: Don’t use connectedAndroidTest task in CI Your task depends on assembleAndroidTest Your task spawns several processes Task type Exec has commandLine for shell

Slide 9

Slide 9 text

Test Sharding: Gradle Prepare Android Prepare Android Application Manager Application Manager Prepare Android Application Manager Check Timeout

Slide 10

Slide 10 text

Prepare 1 Android: AWS CLI Start Genymotion Instance Capture Logcat ADB connect Record Screen Ready

Slide 11

Slide 11 text

Company AWS infrastructure ... Virtual Private Cloud 1 Virtual Private Cloud n

Slide 12

Slide 12 text

VPC Subnet x (location) Security Group y (firewall) EC2 Instance

Slide 13

Slide 13 text

AWS CLI: Find the Subnet. Where the instance will be. Find the Security Group. The instance firewall. Both need to belong to the same VPC. Find the Amazon Machine Image. The instance operating system. Genymotion-on-Demand is 1 AMI for each Android version

Slide 14

Slide 14 text

Useful AWS CLI: aws ec2 describe-vpcs aws ec2 describe-subnets aws ec2 describe-security-groups aws ec2 describe-images (takes several seconds) aws ec2 run-instances aws ec2 wait instance-running aws ec2 terminate-instances

Slide 15

Slide 15 text

How to start using Genymotion-on-Demand: Watch genymotion.com/help/cloud-PaaS/tutorial Talk to DevOps and SRE teams in your company AWS CLI documentation Don’t fight sed, embrace jq JSON processor.

Slide 16

Slide 16 text

Need your own security group: CloudFormation .yml GenymotionSecurityGroup: Type: AWS::EC2::SecurityGroup SecurityGroupIngress: - SourceSecurityGroupId: !Ref CISecurityGroup FromPort: 5555 ToPort: 5555 IpProtocol: tcp

Slide 17

Slide 17 text

Wait for Android to boot: adb connect to port 5555 May need to be retried adb wait-for-device shell getprop sys.boot_completed Loop until it returns 1

Slide 18

Slide 18 text

Prepare 1 Android: AWS CLI Start Genymotion Instance Capture Logcat ADB connect Record Screen Ready

Slide 19

Slide 19 text

Capture Logcat: adb -s IPAddress:5555 logcat 1> build/myfolder/myfile.txt 2>&1 Does not return until you kill it. Build must continue. Needs background process Once for every Android you prepare.

Slide 20

Slide 20 text

Record Screen: adb -s IPAddress:5555 shell screenrecord /sdcard/myfile.mp4 Returns after 3 minutes. Needs loop. Build must continue. Needs background process. Stop with kill -SIGTERM or video is truncated.

Slide 21

Slide 21 text

Useful Gradle: ProcessBuilder pb = new ProcessBuilder(command.split(' ')) Process process = pb.start() process.text.eachLine {println it} process.waitFor() def pid = process.class.getDeclaredField('pid').getInt(process) pid can be stored in temporary file.

Slide 22

Slide 22 text

Test Sharding: Gradle Prepare Android Prepare Android Application Manager Application Manager Prepare Android Application Manager Check Timeout

Slide 23

Slide 23 text

Android application manager runs Espresso: ADB install application ADB install test APK developer.android.com/studio/test/command-line.html Once for every Android you prepared.

Slide 24

Slide 24 text

Instrumentation command line: adb -s IPAddress:5555 shell am instrument -w -e numShards (number of Androids started) -e shardIndex (which one of the Androids) -e listener (generate JUnit report) -e coverage true -e coverageFile (measure test coverage) Useful: de.schroepf.androidxmlrunlistener.XmlRunListener

Slide 25

Slide 25 text

How: Push Code CI Trigger Run Tests Build APK Publish Results

Slide 26

Slide 26 text

Publish Build Results: CI system configured to retrieve artifacts. adb pull from each Android: - ALL screen record videos - Code coverage files .ec - JUnit test report .xml NOW YOU CAN TERMINATE EACH ANDROID INSTANCE

Slide 27

Slide 27 text

Quarterly: Use new version of Genymotion-on-Demand AMI changes needed: ➔ Enable ADB ➔ Disable animations ➔ Enable virtual keyboard Optional: Change resolution

Slide 28

Slide 28 text

Useful Android commands setprop persist.sys.usb.config adb su root settings put global window_animation_scale 0 su root settings put global transition_animation_scale 0 su root settings put global animator_duration_scale 0 su root settings put secure show_ime_with_hard_keyboard 1

Slide 29

Slide 29 text

Use Packer to make new AMI JSON configuration to execute Shell on EC2 instance. Will spawn instance from Genymotion AMI. Runs scripts to configure instance. Saves a snapshot as a new AMI. Launch instances of that new AMI to run tests. AMI snapshot will be 6GB

Slide 30

Slide 30 text

packer.json builder type: amazon-ebs ssh_username: shell (as per Genymotion release notes) subnet does not need to be same as used in CI security group does not need ADB 5555. Does need SSH 22 provisioner type shell, with .sh scripts Reboot instance after resolution change

Slide 31

Slide 31 text

Remember: ➔ AWS Basics: AMI, EC2, VPC, Security Group ➔ Build your own AMI: Packer, Shell ➔ Rebuild infrastructure at will: CloudFormation ➔ Need permissions in AWS and CI tool. ➔ Gradle: spawn several processes. ➔ Espresso: Launch instance, wait for it, adb, record everything ➔ TERMINATE INSTANCES

Slide 32

Slide 32 text

More: starlingbank.com/careers starlingbank.com/blog starling bank developer podcast community.starlingbank.com developer.starlingbank.com

Slide 33

Slide 33 text

Thanks: Deborah Munsi @ Genymotion Jean-Charles Leneveu @ Genymotion Engineering group @ Starling Kelly Tran @ Badoo Net-a-Porter Blame: Teresa Ng @ Starling

Slide 34

Slide 34 text

Questions