【问题标题】:Android Espresso Black Box TestingAndroid Espresso 黑盒测试
【发布时间】:2017-09-10 06:10:31
【问题描述】:

我正在尝试使用 Android Espresso 对第 3 方 apk 文件进行黑盒测试。我无权访问第 3 方 apk 文件的源代码。

所以,我可以使用UIAutomatorViewer 获取 UI 元素 ID。但是,在 Espresso 文件中,我无权访问“R”。

所以当我调用onView(withId(R.id.<ui id>)) 时,它返回一个错误:

包 R 不存在

例子:

onView(withId(R.id.fragment_onboarding_skip_button)).perform(click());

【问题讨论】:

    标签: android android-espresso black-box-testing


    【解决方案1】:

    可以通过创建从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());
    }
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多