Test Your Navigation App Without Leaving the Room

One of the biggest challenges in mobile testing is testing a navigation app.

It's actually still common to find testers and developers going on a "test drive" and traveling between cities to test the navigation functionality of their app.

It's more efficient to automate this process. However, doing automated testing on a navigation app can get complicated because you cannot build automated tests on "moving" devices.

In this post, I'll show how to test a navigation app in your lab and explain how to create a test automation script that injects routing data into the device.


The following video shows an automation script for testing a navigation app on a mobile device.

How to generate routing data

1. Open Google Maps and set up the route between two addresses; copy the URL

2. Go to http://www.gpsvisualizer.com/convert_input, set up the output format to GPX and paste the link in the URL field

GPSConverterTool
Press the convert button to get the GPX file and copy it on your local PC.

Use the following code to read the data from the GPX file and to inject it into the device:

package ResponsiveWebTest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.openqa.selenium.remote.RemoteWebDriver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class GPS {
	
    static LinkedList locations = new LinkedList<>();
  
    public static void main(String[] args) {
    	// get the GPS points for the file we created ( GPX file) 
        readData();
        // connect to Perfecto Mobile 
        String deviceID = "483982dfdfs4wsdef";
		RemoteWebDriver webdriver = util.getRWD(deviceID, "MobileOS"); 
        // loop over the GPS data and inject it to the device
        ListIterator listIterator = locations.listIterator();
        while (listIterator.hasNext()) {
            String poi = listIterator.next();
            setLocation(poi,webdriver);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    
    // this function set the location using executeScript command
    private static void setLocation(String address,RemoteWebDriver d )
	{
		Map params = new HashMap();
		params.put("address", address);
		d.executeScript("mobile:location:set", params);
	}
    public static void  readData()
    {
        try {
            // use the GPX file 
            File f = new File ("C:\\GPS\\home_work.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(f);
            NodeList nList = doc.getElementsByTagName("trkpt");
            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;
                    locations.add(eElement.getAttribute("lat")+","+ eElement.getAttribute("lon"));
                }
            }
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Tags: ,

About the Author

Uzi joined Perfecto Mobile seven years ago after a fifteen year career as a software developer and manager at IDF, Netrialty, Comverse and Sundisk. Over the past seven years, Uzi has helped grow Perfecto by managing expanding R&D teams and leading sales engineering teams. His fields of expertise include agile methodologies, mobile application testing, automation tools, and defining customer projects and on-boarding.

Share Your Thoughts!

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

Love to learn about creating top notch digital experiences?

Get the latest news, tips and articles delivered right to your inbox.