How To Validate Whether Opened Correct Activity - Espresso
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.
Solution 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?
Solution 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);
Post a Comment for "How To Validate Whether Opened Correct Activity - Espresso"