Biometric authentication is now available for all products!

Simulate GPS Movements Using GMTool & Genymotion Shell

Written by Lydwine Camus – QA Engineer at Genymobile

This tutorial will tell you how to use Genymotion to simulate device location changes. More specifically, it will explain how to plan a route – for say a car trip, show you how to generate a script and how to automatize every single GPS movements.

But first, let’s take a look at what is automation and what it can bring to app development.

What is the main goal of automation ?

Automation is a great way to save time and improve product quality.

Take, for example, automated unit tests and functional tests: much faster than manual tests, they allow developers and quality engineers to make sure there are no regressions. Automation can also improve your product quality by running the same scripts in different environments, testing on many platforms and devices.

That’s where Genymotion comes into play

Genymotion offers two features to automate testing: GMTool and Genymotion Shell. By combining these 2 tools many automation possibilities await.

What is GMTool and what can I do with it ?

GMTool is a command line tool that allows you to use every command of Genymotion and virtual devices in order to automate a series of actions. It can be started by running gmtool from a command prompt, from the installation path of Genymotion.

Here are examples of the main commands:

Look up the device templates list: gmtool admin templates

Choose a template, then create and start a device:
• Creating a device: gmtool admin create
• Starting a device: gmtool admin start

Your device is ready to be used!

When you are done using it, you can stop and delete it using these commands:
• Stopping a device: gmtool admin stop
• Deleting a device: gmtool admin delete

What is Genymotion Shell and what can I do with it ?

As the name indicates, Genymotion Shell is a shell which allows you to script the modification of sensor statuses and values.

You can interact with different kind of sensors, such as battery, GPS, Network, phone, baseband… For example, you can use Genymotion shell to activate the GPS and set your own values for the latitude, longitude, altitude… Just like this:

Activate the GPS: gps setstatus enabled
• Set latitude: gps setlatitude 25.2289
• Set longitude: gps setlongitude 145.4578

With these simple commands we can imagine multiple tests like calculating the distance between two points, simulating a location, simulating a trip step by step (by foot, by car, by train…).

What is Genymotion Shell and what can I do with it ?

Let’s see step by step how we can create and emulate a trip by car::

1. Choose a programming language

For this example we choose to use Python.

2. Plan your route

We can easily do that using Google Maps. So head over to Google Maps, select the car option and start planning a route. Once your route is defined, copy the page URL link in the address bar to your clipboard.

3. You need to convert your route to a .gpx file

GPX is an XML based format for GPS tracks. To convert your route we’d propose you to visit gpsvisualizer.com/convert_input. You can ignore most of the available options. Just select Gpx and paste the Google Maps URL into the field labelled “provide the URL of a file on the Web” and press Convert button.

gpx-interface

A new page is displayed which shows you the .gpx content and gives you the option to download it.

4. You need something to be able to manipulate your .gpx file

Using Python we can use the gpxpy library, which allows us to parse and manipulate GPX files. The main goal of this manipulation of gpx file is to get all GPS coordinates of your route (latitude and longitude) to finally set them in a device using Genymotion shell.

We can obtain something like this:

Some explanations

• Line 8 and 9: open and parse the gpx file to create a gpx object.
• Lines 10 to 15: create a subprocess calling Genymotion shell.
• Lines 16 to 33: activate the gps and use the gpx object to get latitude and longitude points. Then set these values to Genymotion Shell
• Line 28: Do a sleep during X second (more on this below)
• Line 34 to 38: we properly close our subprocess

Why are we using a X second sleep line 28?

Without sleep the script would run almost instantly so as to emulate a certain speed (here about 100 km/h), therefore we need to use the sleep() function to wait between each point.

This value (sleep = X) depends on
• The distance between 2 points
• The speed you want

Considering Speed = Distance / Duration
We have Duration of a sleep() = distance between 2 points / Speed

To see the result:

1. Start genymotion
2. Start a device
3. Install openGapps corresponding to your android device version
4. Install and launch Google maps
5. Run this script

You should see your current position moving on the map following your defined route.

demo-automation

Select Product Portal

SaaS Platform

Access to our SaaS solution and use virtual machines in the cloud on any web browsers.

Or

Or

Desktop Platform

Access to manage your Genymotion Desktop licenses, your invoices and account information.

Select a Cloud provider Marketplace

How to get a quote for multiple Business Licenses?

  1. You need a Genymotion Desktop account. If you haven’t one yet, you can create it here.
  2. After creation and activation, or if you already have an account, follow this link.
  3. Add the number of desired licenses to your shopping cart and click “Continue to Billing”
  4. Add a shipping address, or select one if you already created one.
  5.  In the next page, click “Get a quote”:
    Payment details
  6. A quote will be automatically generated in PDF format.

Genymotion Device Image for Cloud providers
- Private Offer -

Genymotion Device On-premise
- Contact Us -

Genymotion SaaS
- Increase Maximum Simultaneous devices -

Genymotion SaaS Annual Plan
- Get a Quote -

Genymotion SaaS Premium Plan
- Get a Quote -

Personal Use - Free

Genymotion Desktop for personal use is not suitable for trial or POC: you will not get any assistance and some features will be disabled. If you have already selected “personal use” and wish to get a trial license, please contact our Sales at [email protected].

Technical support is not available with Genymotion Desktop free edition for personal use. For more details, please refer to Genymotion conditions of use (Personal Use).

The following features are not available in personal use mode:

Follow these steps to get Genymotion Desktop and activate personal use mode:

  1. Go to the Download page and get the latest version for your system.
  2. Follow the instructions from Genymotion Desktop quickstart guide to install Genymotion Desktop.
  3. Launch Genymotion and click CREATE to create an account. You should receive an activation email within an hour. If not, make sure to check your spam.
  4. After activating your account, return to Genymotion and log in with your credentials.
  5. Select personal use when prompted.
  6. Read Genymotion Desktop quickstart guide carefully to setup Genymotion for your needs.

Individual Offer Order

This offer is strictly reserved for personal use or individual workers (freelancers).

Educational Offer Order

The Educational subscription is restricted to:

  • schools, teachers or students who wish to use Genymotion Desktop for tuition
  • students who wish to use Genymotion Desktop for a school project

It is subject to valid proof (student card, teacher card, etc.)