Automation features

Genymotion Cloud offers automation features useful for automating tests and continuous integration, regardless of your test framework (Espresso, Robotium, Selenium, Appium) or continuous integration server (Jenkins, TeamCity, Travis or Bamboo). Those features are exposed through a development tools: gmsaas. It is a command line tool specific to Genymotion that allows you to manage the lifecycle of your virtual devices and enable any ADB interactions between your environment and your instance.

This chapter details how to automate actions in Genymotion Cloud using gmsaas.

Automating actions with gmsaas

This section explains how to automate your instrumented tests from your desktop and run them locally or in using the command line tool gmsaas for Genymotion Cloud. Please refer to gmsaas command line tool for gmsaas installation and usage.

Prerequisites

To run instrumented tests from your desktop, you must be authenticated on gmsaas.

Running instrumented tests

  1. Create and start your instance by running:

    gmsaas instances start <RECIPE_UUID> <INSTANCE_NAME>
    

    <RECIPE_UUID> is the recipe identifier and <INSTANCE_NAME> is the name you wish to give to the instance. Once up, the command returns and shows the <INSTANCE_UUID>.

    The list of available recipes can be retrieved using this command: gmsaas recipes list.

  2. Connect the instance to ADB

    gmsaas instances adbconnect <INSTANCE_NAME> [--adb-serial-port <VALUE>]
    
  3. Run your instrumented tests using:

    • ./gradlew connectedAndroidTest
    • AndroidStudio in Gradle toolbox: Tasks > verification > connectedAndroidTest

    You can view your tests running in the virtual device by signing in to Genymotion Cloud.

  4. Once your tests have run, stop the virtual devices using:

    gmsaas instances stop <INSTANCE_UUID>
    

    <INSTANCE_UUID> is the UUID (not the name!) of the instance used for the test. All data generated on the virtual device during the tests are destroyed.

Running instrumented tests with Genymotion Java API

To run your instrumented tests, you can also use the Genymotion Java API in order to automate the modification of sensor values such as battery, GPS, ID, SMS, calls... For more information on the implementation of the Genymotion Java API, please refer to the official documentation. A sample project is available at https://github.com/Genymobile/genymotion-binocle.

Running instrumented tests from Jenkins

This section explains how to automate your instrumented tests from your Jenkins continuous integration server using the for Genymotion.

Prerequisites

Configuring a Jenkins job with gmsaas

  1. To configure the Jenkins job that will run your instrumented test, from Jenkins, go to menu Configure.

  2. In Source Code Management, enter the location of the application source code. Management

  3. From the Build section:

    1. Add Execute shell to run commands and add the following commands:

      <GMSAAS_PATH>/gmsaas auth login <EMAIL> <PASSWORD>
      

      <GMSAAS_PATH> is the location of gmsaas on your Jenkins, <EMAIL> and <PASSWORD> are the email and password of your Genymotion Cloud account. This authenticates you to Genymotion.

      <GMSAAS_PATH>/gmsaas instances start <RECIPE_UUID> <NAME>
      

      <RECIPE_UUID> is the device recipe/template uuid (you can get all the recipes by using the command gmsaas recipes list) and <NAME> is the name you wish to give to the instance.

      Please note that <NAME> is only use as a tag. You should not use it to issue commands from gmsaas to an instance. Use the instance UUID instead.
      Please refer to section Automating actions with Gmsaas for details.

    2. Add Invoke Gradle script to run your instrumented test.

    3. Tick Root Build Script Dir.

    4. To have more logs, in Switches, enter --debug --stacktrace

    5. In Tasks, add connectedAndroidTest Gradle

  4. From the Post Build section:

    1. Add Publish JUnit test result report & Publish HTML reports to get test reports. Jenkins
    2. Add Execute a set of scripts to stop the device where the tests were run. In Build steps, add Execute shell section and add the following command: <GMSAAS_PATH>/gmsaas instances stop <UUID> where <UUID> is the UUID of the virtual device you created (not the <NAME>!).

Running the builds

You can run the builds manually by clicking Build with Parameters or have it automatically built by configuring a scheduled build.

Viewing test reports

Once your tests have run, you can view your test reports from Test Report.