我的活动显示了一张地图(使用当前位置),我必须对此进行测试。
为此,需要ACCESS_FINE_LOCATION权限。我尝试将UiAutomator用于:
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) {
}
}
}
}
它在本地运行,但不适用于Travis CI。当我运行测试时,这很简单:
onView(withId(R.id.mapView)).check(matches(isDisplayed()));
Travis CI返回一个:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching