Create your test infrastructure with Genymotion Cloud SaaS and Terraform

Thomas CARPENTIER
Genymobile
Published in
4 min readJan 13, 2020

A little introduction…ok long introduction…

I am a QA Software Engineer for Genymotion products. Genymotion is available on Desktop (macOS, Windows, Linux), on famous Cloud providers (AWS, GCP, Alibaba) and also on our SaaS platform. We provide several Android versions, from 4.4.4 to 9.0. So, when our software engineers develop a new feature, we (QA team) need to test it on each Android version, on each provider. Even if validation takes time, the most boring part is to start, stop and configure the Android instances all the time. It is a very repetitive task!

As I started to create automated tests for Genymotion Cloud PaaS (AWS, GCP, Alibaba), I discovered a wonderful tool: Terraform. It allows you to manage your infrastructure as code, just write a configuration file with your needs, apply it and your new instance is created… That’s perfect! I’ve added it to our CI (Jenkins in our case): when the job starts, it creates the test infrastructure we need, and runs tests on it. And it is always the same configuration.

Meanwhile, we have released Genymotion Cloud SaaS, a cloud-based Android device emulators available on our private cloud.

And here we are again: start, stop instances, over and over…. So I looked at Terraform and I started to implement a new provider in order to create a test infrastructure on Genymotion Cloud SaaS with Terraform.

End of introduction. Time to practice!

Setup Genymotion Cloud SaaS Account and install prerequisites

  1. Create a Genymotion Cloud Saas account here.
  2. Install Android SDK.
  3. Install gmsaas. It is our tool to manage Genymotion Cloud SaaS instances. It is a Python package, so you can download it using pip3 install gmsaas.
  4. Configure the path to your Android SDK with: gmsaas config set android-sdk-path <SDK-PATH>.

Install Terraform

  1. Download Terraform from here.
  2. Read this guide on how to install Terraform depending your operating system

Build and Destroy your first instance using Terraform

Now we have created our Genymotion Cloud SaaS account, downloaded and configured gmsaas; let’s start our first Genymotion instances using Terraform.

Create a new file, called `genymotion.tf`.

In the provider block, we call the Genymotion provider plugin from Terraform. We set the credentials from the user we have created.

Then we use the resource identifier “genymotion_cloud” to state that we are trying to start a Genymotion Cloud SaaS instance followed by the name identifier. Here, we use Android90 because we will start an Android 9.0 instance.

Fill the recipe_uuid argument. A recipe is a template with a given Android version, display size, density and specifications (CPU, memory, storage) which generally matches those of a real device. You can get the list of all recipe UUID using gmsaas recipes list. Select the recipe UUID that best fits your needs.

Fill the name argument. It is the name of the instance you want to create. It is just declarative!

Now, it is time to run terraform init command. It will download and initialize the Genymotion provider plugin.

Continue with terraform plancommand. It describes what Terraform does before applying.

Ready to create instances? Run terraform apply command

Let’s go to https://cloud.geny.io ; you can see that three instances have started.

Once you have finished your tests, it is time to stop thoses instances. So we will run terraform destroy command in order to destroy the test infrastructure.

Note: a powerful Terraform feature is the ability to create/destroy resources in parallel. It gives you a faster creation/destruction cycle for your test infrastructure!

Conclusion

Now that you are able to create a test infrastructure on Genymotion Cloud SaaS with Terraform, you can run your Android Tests (Appium, Espresso or other test automation frameworks) with several devices, in parallel.

For more information about parallel testing, you can refer to our previous blogpost: https://medium.com/genymobile/how-to-run-parallel-tests-using-genymotion-cloud-saas-8858ffe0947f

You can also find more information about the Genymotion providers on Terraform website: https://www.terraform.io/docs/providers/genymotion/index.html

Thanks for reading!

--

--