Test a navigation app without leaving the room
One of the biggest challenges in mobile testing is testing a navigation app. While it is common to find testers and developers going on a "test drive" to test the app, some teams even travel between cities for this purpose. Automating testing on a navigation app is even more complicated because you cannot build automated tests on “moving" devices.
This article demonstrates how to test a navigation app and explains how to create a test automation script that injects routing data into the device.
The following video shows the automation script running against the device.
To generate routing data:
-
Open Google Maps, set up the route between two addresses, and then copy the URL.
-
Go to http://www.gpsvisualizer.com/convert_input, set the output format to GPX, and paste the link into the URL field.
-
Click Convert to get the GPX file and copy it to your local machine.
-
Use the following code to read the data from the GPX file and inject it to the device.
Copypackage GPS;
import java.io.File;
import java.io.IOException;
import java.util.AbstractList;
import java.util.LinkedList;
import java.util.ListIterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
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;
import com.perfectomobile.selenium.MobileCoordinatesLocation;
import com.perfectomobile.selenium.MobileDriver;
import com.perfectomobile.selenium.MobileLocation;
import com.perfectomobile.selenium.api.IMobileDevice;
public class GPSTest {
static LinkedList<String> locations = new LinkedList<>();
public GPSTest() {
}
public static void main(String[] args) {
readData();
// connect to Perfecto Mobile
MobileDriver PMdriver = new MobileDriver();
//select a device
IMobileDevice device = PMdriver.getDevice("57AF4ED9");
// loop over the GPS data and inject it to the device
ListIterator<String> listIterator = locations.listIterator();
while (listIterator.hasNext()) {
MobileLocation location1 = new MobileCoordinatesLocation(listIterator.next());
device.setLocation(location1);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
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();
}
}
}