[英]Android Espresso Black Box Testing
我正在尝试使用Android Espresso在第三方apk文件上进行Black Box测试。 我无法访问第三方apk文件的源代码。
所以,我能够使用UIAutomatorViewer
获取UI元素ID。 但是,在Espresso文件中,我无法访问“R”。
所以当我调用onView(withId(R.id.<ui id>))
,它返回一个错误:
包R不存在
例:
onView(withId(R.id.fragment_onboarding_skip_button)).perform(click());
它可以通过创建从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());
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.