我正在尝试使用对第三方apk文件进行黑盒测试。我无法访问第三方apk文件的源代码。
因此,我能够使用UIAutomatorViewer
获得UI元素I。但是,在Espresso文件中,我没有访问"R“的权限。
因此,当我调用onView(withId(R.id.<ui id>))
时,它将返回一个错误:
包R不存在
示例:
onView(withId(R.id.fragment_onboarding_skip_button)).perform(click());
发布于 2018-03-26 16:59:02
可以通过创建一个从ID名称中提取整数ID的方法来解决这个问题:
...
public int getId(String id) {
Context appContext = InstrumentationRegistry.getTargetContext();
return appContext.getResources().getIdentifier(id, "id", "<applicationId>");
}
@Test
public void testSomething() {
//here just pass the ID name
onView(withId(getId("fragment_onboarding_skip_button"))).perform(click());
}
...
https://stackoverflow.com/questions/46137785
复制相似问题