Android, how to test Google Map

android, android-espresso, android-testing

Solution

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

Problem

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?

Original source

Related problems