Espresso - check which Activity is opened using intent on button press?
<p><strong>Is it possible to trace which Activity is opened after a certain button is pressed?</strong><br>I have a test in which, <strong>when a button is clicked / pressed</strong>, it <strong>sends a request to the server</strong>. Till the time the request is sent, <strong>it opens an Activity</strong>. <strong>To verify the successful execution</strong> of the test, I need to check what is the open Activity.<br> <br>Example of my test:</p>

<p>Check which Intent is opened in Espresso ---</p>

<pre><code> private void startTest() {
    recreateAuthData(InstrumentationRegistry.getTargetContext(), "d78269d9-9e00-4b8d-9242-815204b0a2f6", "3f32da21-914d-4adc-b6a1-891b842a2972");

    InstrumentationRegistry.getTargetContext().getSharedPreferences(ActivitySplashScreen.class.getSimpleName(),
            Context.MODE_PRIVATE).edit().putInt(ActivitySplashScreen.PROPERTY_APP_VERSION, ActivitySplashScreen.getAppVersion(InstrumentationRegistry.getTargetContext())).commit();
    InstrumentationRegistry.getTargetContext().getSharedPreferences(ActivitySplashScreen.class.getSimpleName(),
            Context.MODE_PRIVATE).edit().putString(ActivitySplashScreen.PROPERTY_REG_ID, "testKey").commit();

    mActivityRule.launchActivity(setIntent());
    // inputPinCode("2794");
}

@Test
public void testIdent() {
    startTest();
    onView(withText("ПРО")).perform(click());
    putDelay(500);
    onView(withId(R.id.get_pro)).perform(click());
    onView(withText("Авторизация по паспортным данным")).perform(click());
    putDelay(500);
    closeSoftKeyboard();
    onView(withId(R.id.btn_goto_passport)).perform(click());
    onView(withHint("Серия и номер паспорта")).perform(replaceText("9894657891"));
    onView(withHint("Дата выдачи паспорта")).perform(replaceText("17032014"));
    onView(withHint("Дата рождения")).perform(replaceText("31091994"));
    onView(withHint("СНИЛС")).perform(replaceText("54665285919"));
    putDelay(500);
    Log.d("TestWidget", hasComponent(hasShortClassName("ActivityMain")).toString());
    onView(withId(R.id.btn_next)).perform(click());
    // some code which check which activity is display now
    putDelay(500);

}
</code></pre>