How to detect and click on Mapbox markers in native Android application?

Viewed 999

We are trying to create automated tests for Mapbox's Maps SDK for Android based native mobile application. The automated tests need to determine the number of markers present on the screen, the number of marker clusters present on the screen, click on marker or cluster etc.

When looking at the Mapbox maps on Android application through UIAutomatorViewer or through Appium inspector, the markers visible on the map are not shown in the object hierarchy.

What can the Android native mobile application development team do to surface the markers/clusters so that they are visible to Appium?

Alternately, what other options can the automation team explore to develop automated tests? Espresso is not ideal as automation team does not have access to source code for the native mobile application.

Please see Mapbox demo application's -> Annotations -> Draw a marker for an example of a marker that we would like to detect and click on.

2 Answers

Since the Mapbox SDK uses OpenGL rendering, not native components, most test automation frameworks won't be able to recognise UI elements like the markers or clusters you add to the map.

There are some testers using image recognition from the Accelerated-KAZE Features project to find items on screen in order to count and select them. Some example code can be found at https://github.com/bitbar/bitbar-samples/tree/master/image-recognition

Another approach may be to have the mobile app developers include testing hooks that allow your testing code to use the Mapbox API to query rendered features. Mapbox documentation for that is here: https://www.mapbox.com/android-docs/maps/overview/query/#query-rendered-features

I had come across this scenario earlier that an element, even when it's displayed on the screen, was not highlighted when selected from Appium inspector.

Later, when I scanned the complete hierarchy tree clicking on each node was I able to find the element.

I would suggest you to click on every node and check, the marker will be there in the hierarchy tree. It's just that inspector cursor is not able to highlight it.

Related