How to validate whether opened correct activity - Espresso

隐身守侯 提交于 2019-12-13 07:20:54

问题


I created android UI test with espresso and done Button click and opening an Activity. Now I want to validate whether opened correct activity or not.


回答1:


Use espresso-intents to validate that.

The usage is:

intended(hasComponent(NewActivity.class.getName()));

You can read this thread for more details on that: Espresso - check which Activity is opened using intent on button press?




回答2:


You want get the instance of activity rule which you have register and compare it with the activity which you want.

// Define activity rule
    @Rule
        public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>
                MainActivity.class);


    // compare activity rule activity with the activity you want to check.

    Assert.assertEquals(mActivityRule.getActivity(), MainActivity.class);


来源:https://stackoverflow.com/questions/43153146/how-to-validate-whether-opened-correct-activity-espresso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!