Using UiAutomator to test if map has loaded or not


I am new to testing in android. I have a map activity, which is called after some events in the MainActivity and a map appears in the screen. I am not able to figure out how to test whether the map appears or not. I understand its not possible with espresso, but have read somewhere that its possible with UiAutomator. How to use UiAutomator for the same..?


You can set the content description of the View hosting the map to indicate its “readiness”.

    SupportMapFragment mapFragment 
            (SupportMapFragment) getSupportFragmentManager()
    mapView  mapFragment.getView();
    mapView.setContentDescription("MAP NOT READY");
    // you may need to preserve existing description

public void onMapReady(GoogleMap googleMap) {
    mapView.setContentDescription("MAP READY");

Then, on your test

mDevice.wait(Until.hasObject(By.desc("MAP READY")), timeout);

Answered By – Diego Torres Milano

Leave a Comment