[英]Android Espresso Black Box Testing
I'm trying to conduct Black Box testing on a 3rd party apk file using Android Espresso. 我正在尝试使用Android Espresso在第三方apk文件上进行Black Box测试。 I don't have access to the source code of the 3rd party apk file. 我无法访问第三方apk文件的源代码。
So, I'm able to get the UI element ids using UIAutomatorViewer
. 所以,我能够使用UIAutomatorViewer
获取UI元素ID。 However, in the Espresso file, I don't have access to "R". 但是,在Espresso文件中,我无法访问“R”。
So when I'm calling onView(withId(R.id.<ui id>))
, it's returning an error: 所以当我调用onView(withId(R.id.<ui id>))
,它返回一个错误:
package R does not exist 包R不存在
Example: 例:
onView(withId(R.id.fragment_onboarding_skip_button)).perform(click());
It can be solved by creating a method extracting an integer ID from the ID name: 它可以通过创建从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.