Categories
Status

Android UI Testing in the cloud with Genymotion Cloud SaaS

This is a follow up to a previous unfinished post: http://whereisdarran.com/2020/03/running-x86-android-emulators-in-the-cloud-incomplete/

The immediate suggestion most people will have for running UI tests in the cloud is Firebase Test Lab. Firebase Test Lab is a great solution, but I need something that has the following capabilities:

  • The ability to install multiple arbitrary APK’s that are not the app under test
  • The ability to clone customized emulators
  • The ability to save and resume emulators across test runs

Why do I need these capabilities?

I am developing an Android application that runs on and integrates with a Point of Sale platform made by Clover. Specifically, I need to test my application in a test environment that mimics the Clover Station 2018 (pictured below)

Clover provides APK’s that allow you to re-create the operating environment of the Station 2018 on an emulator.

Using Genymotion Cloud we can re-create the Station 2018 environment on a tablet emulator image and then save that emulator image and use it or clone it later. This is something not available on Firebase Test Lab.

Below is a screenshot of a tablet emulator image configured as a Clover Station 2018 running in Genymotion Cloud SaaS.

Once we have configured the emulator, we can save the state of the emulator and give it a meaningful name.

The recipe UUID allows us to start a new instance of this emulator image using the recipe UUID. Genymotion provides a CLI tool that allows us to start an instance from the command line using the following command:

gmsaas instances start c9246a83-4f38-4742-a11f-42b5b765dbdc instanceToTestWith

That will start an instance that we can connect to over ABD. We can also connect to the display through the Genymotion Cloud console.

The CLI tool also provides a command to connect ADB to the instance that was just started. After connecting over ADB, we can see that the Clover packages are installed and the emulator is a perfect clone of the image we previously prepared:

Darrans-MBP:cef darrankelinske$ gmsaas instances start c9246a83-4f38-4742-a11f-42b5b765dbdc instanceToTestWith
9f8e32ea-543c-4d64-8609-b016165a6754
Darrans-MBP:cef darrankelinske$ gmsaas instances adbconnect 9f8e32ea-543c-4d64-8609-b016165a6754
localhost:55813
Darrans-MBP:cef darrankelinske$ adb devices
List of devices attached
localhost:55813	device

Darrans-MBP:cef darrankelinske$ adb shell
vbox86p:/ # pm list packages -3                                                                                                            
package:com.fivestars.mpos.clover
package:com.clover.register
package:com.example.android.apis
package:com.clover.auths
package:com.clover.crypt
package:com.clover.setup
package:com.clover.terminal.sale
package:com.android.gesture.builder
package:com.clover.engine
package:com.clover.launcher
package:com.clover.payment.builder.pay
vbox86p:/ # 

Full command reference: https://docs.genymotion.com/gmsaas/1.x/03_Commands.html

Genymotion also provides a CircleCI orb which makes integrating the emulator into a CircleCI build process straightforward.

https://circleci.com/developer/orbs/orb/genymotion/genymotion-saas

Using the orb we can make a job that runs UI tests on an instance of the emulator image we previously created. The job outlined below will build APKs to test, start a Genymotion emulator instance that is pre-configured as a Clover Station 2018 and then run a specific set of UI tests. Once the test are complete, the emulator instance will be stopped.

  uiTest:
    executor: android
    steps:
      - checkout
      - run:
          name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
          command: |
            sudo chmod +x gradlew
      - restore_cache:
          keys:
            - gradle-{{ checksum "app/build.gradle" }}
      - run:
          name: Build APKs to test
          command: |
            ./gradlew aCD aCDAT
      - genymotion-saas/setup
      - genymotion-saas/start-instance:
          recipe_uuid: "c9246a83-4f38-4742-a11f-42b5b765dbdc"
      - run:
          name: Install APKs to test
          command: |
            ./gradlew iCD iCDAT
      - run: (! adb shell am instrument -w -r  --no-window-animation  -e debug false -e class 'com.fivestars.yoshi.feature.discount.view.DiscountActivityTest' com.fivestars.mpos.clover.test/androidx.test.runner.AndroidJUnitRunner | tee /dev/tty | grep -q FAILURES!!!)
      - genymotion-saas/stop-instance

And with that, we have accomplished what we needed. We are now able to test our application in CI using an emulator that is pre-configured with the environment we need to test in.

Thank you for reading! Please let me know what you think!

Genymotion offers a free hour of Cloud SaaS.

There is an introduction video on how to get started below. Give it a try!

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.