如何使用Espresso测试框架在AlertDialog中选中该项目

时间:2017-03-14 10:42:00

标签: android testing android-espresso android-instrumentation

所以,我有一个AlertDialog,其中包含可选项列表。其中一个总是被选中。在仪器测试中,我想打开对话框并检查是否选择了具有特定文本的项目。我尝试使用以下代码段无效:

push.on('notification', (data) => { this.ngZone.run(() => { // update array }); });

1 个答案:

答案 0 :(得分:0)

I hope help full for you

    ViewInteraction customTextView = onView(
                allOf(withId(R.id.tv_switch), withText("Switch care"),
                        withParent(allOf(withId(R.id.ll_care),
                                withParent(withId(android.R.id.content)))),
                        isDisplayed()));
        customTextView.perform(click());

        ViewInteraction mDButton = onView(
                allOf(withId(R.id.buttonDefaultPositive), withText("Continue"), isDisplayed()));
        mDButton.perform(click());