Friday, March 5, 2010

Automate Google Maps on Android

I own an IPhone and I really like it. But I don’t like Apple ‘close garden’ strategic.

So the Google launch of Android really made me happy.

Test Automation was well considered in the design of the Android. You have an automation API that is part of the operation system. But this is mainly used for unit test of applications developed by you.

What if you would like to automate application like ‘Google Maps’?

SeeTest from Experitest was already presented in my last port. I took it to a test drive in automating ‘Google Maps’. I don’t have a real device so I used the Android emulator.

The first challenge is to create a test that launch the ‘Google Maps’ application, search for a location and verify it was found in the map.

1. Start by crate new project and set the application title:
image

I remove the additional avd information in the title so it will work on any android emulator.

2. Then I capture the main desktop scene and extract the ‘Maps’ Icon. 
image

Now the default of the ‘Extract Element’ is to use the ‘strict’ scan algorithm:
image

According to the documentation it’s very fast scan algorithm but it not tolerable to any change.  So if the background changes it will not be identify. To overcome this you can change the scan algorithm to ‘Similarity’, then you can use the sensitivity bar of the algorithm:

image

3. Next I wrote a script that navigate to the application by sending {HOME} and then click on the ‘Maps’ icon, this is how the code export to Python looks like:

import unittest
from ExperitestClient import Client

class Untitled(unittest.TestCase):
    def setUp(self):
       self.host = "localhost"
        self.port = 8888
        self.client = Client()
        self.client.init(self.host, self.port)
        self.client.setProjectBaseDirectory("C:\\Users\\Ben.Miller\\workspace\\project12")
        self.client.setReporter("xml", "reports")

    def testUntitled(self):
        self.client.sendText("{HOME}")
        self.client.click("default", "Maps", 0, 1)

    def tearDown(self):
        self.client.generateReport()

if __name__ == '__main__':
    unittest.main()

From the export script you can see that the test can be execute on remote machine, in our case it’s executed on ‘localhost’.

4. The full script looks as follow:

def testFindNewYork(self):
    self.client.sendText("{HOME}")
    self.client.click("default", "maps", 0, 1)
    self.client.sendText("{F2}")
    self.client.click("default", "Search", 0, 1)
    self.client.sendText("New York")
    self.client.sendText("{ENTER}")
    self.client.sleep(3000)
    self.client.verifyTextFound("default", "New York", false)

I extracted all the ABC characters and used verifyTextFound, that way I can change the city name without any additional work. This is very important as I would like the test to be flexible as possible.

This is how the execution looks like:

5. OK we are done with our first task, Now I would like to see if I can identify all the cities in the map and get their coordination. To do that I extracted the city element, changed the algorithm to similarity and set the sensitivity to around 70%.

This is how the identification map look like:

image 

COOL!

From the site information it look like they have the ability to execute it on real device, but I didn’t try it.

No comments:

Post a Comment