Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, how to test Google Map [duplicate]

So, I have problems with testing my Google Map functionality. In my activty I have callback onMapClick(LatLng latlng) in which there is method to show/hide toolbar. Now, I would like to test it, but I have no clue how to perform click on the map. I tried to use this:

onView(withContentDescription("Mapa Google")).perform(click());

and this:

UiDevice device = UiDevice.getInstance(getInstrumentation());
UiObject map = device.findObject(new UiSelector()
        .descriptionContains("Mapa Google"));
map.click();

but it seams that, it doesn't work. Do you know how can I test this kind of behavior?

like image 234
Panczur Avatar asked May 12 '17 13:05

Panczur


People also ask

Can Google map make a mistakes?

Assuming Google is never wrong Stories of people driving into lakes or streams of molten lava make for good newspaper headlines, but they do demonstrate that while Google Maps is incredibly accurate it can still contain mistakes.


1 Answers

The best way is UiAutomator library , https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html

private UiDevice uiDevice = UiDevice.getInstance(getInstrumentation());
private UiObject mMarker1 = uiDevice.findObject(new UiSelector().descriptionContains("The title of marker"));
try {
    mMarker1.click();
} catch (UiObjectNotFoundException e) {

    e.printStackTrace();
}

for taping on map you can use this

uiDevice.click(x, y);

x and y are the coordinates

like image 148
Ara Hakobyan Avatar answered Sep 20 '22 18:09

Ara Hakobyan