Pan*_*zur 5 android android-testing android-espresso
因此,我在测试 Google 地图功能时遇到了问题。在我的活动中,我有回调onMapClick(LatLng latlng),其中有显示/隐藏工具栏的方法。现在,我想测试它,但我不知道如何在地图上执行点击。我试着用这个:
onView(withContentDescription("Mapa Google")).perform(click());
Run Code Online (Sandbox Code Playgroud)
和这个:
UiDevice device = UiDevice.getInstance(getInstrumentation());
UiObject map = device.findObject(new UiSelector()
.descriptionContains("Mapa Google"));
map.click();
Run Code Online (Sandbox Code Playgroud)
但它接缝,它不起作用。你知道我如何测试这种行为吗?
最好的方法是 UiAutomator 库, 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();
}
Run Code Online (Sandbox Code Playgroud)
要在地图上录音,您可以使用它
uiDevice.click(x, y);
x 和 y 是坐标
| 归档时间: |
|
| 查看次数: |
3528 次 |
| 最近记录: |