mercredi 31 octobre 2018

Allow Travis emulator Runtime Permissions for testing

My activity displays a map (that uses current location) and I have to implement a test for it.

For that, the ACCESS_FINE_LOCATION permission is required. I tried to use UiAutomator with:

private void allowPermissionsIfNeeded()  {
        if (Build.VERSION.SDK_INT >= 23) {
            UiObject allowPermissions = device.findObject(new UiSelector().text("ALLOW"));
            if (allowPermissions.exists()) {
                try {
                    allowPermissions.click();
                } catch (UiObjectNotFoundException e) {

                }
            }
        }
    }

It works locally but not on Travis CI. When I am running my test which is simply:

onView(withId(R.id.mapView)).check(matches(isDisplayed()));

Travis CI returns a:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching

Aucun commentaire:

Enregistrer un commentaire