无法在Espresso测试中执行PressBack

时间:2016-04-19 11:51:31

标签: android-espresso

在一次espresso测试中,我尝试使用以下代码片段点击RecyclerView项目内部。点击项目时,它会启动另一个ACTIVITY。 之后,如果我执行 pressBack ,它就会停留在那一点。

@Test
public void performClickTest(){
        onView(withId(R.id.rv_endless_scroll))
           .check(matches(isDisplayed()))
           .perform(RecyclerViewActions.scrollToHolder(ViewHolderViewMatcher()))
           .perform(RecyclerViewHolderActions());
}


public static class RecyclerViewHolderActions implements ViewAction {
        ViewAction click = click();

        @Override
        public Matcher<View> getConstraints() {
            return click.getConstraints();
        }

        @Override
        public String getDescription() {
            return "";
        }

        @Override
        public void perform(UiController uiController, View view) {
           TextView view = (TextView)view.findViewById(R.id.tv_clickable);

           //on text item click,it Launches new activity (activityOne --> activityTwo)
           click.perform(uiController,view);

            /////////////// To come back on activityOne,pressBack is not working////
            //////////////// Test is getting stuck on below line//////// 
            pressBack();
        }
}

这是在RecyclerView项目和/或 PressBack 操作中执行点击的正确方法吗?

0 个答案:

没有答案