0

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.

Sureshkumar S
  • 193
  • 1
  • 2
  • 13

2 Answers2

0

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);
Jitesh Mohite
  • 31,138
  • 12
  • 157
  • 147
0

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?

Community
  • 1
  • 1
Be_Negative
  • 4,892
  • 1
  • 30
  • 33