Я думаю, что вы должны разделить тестовый сценарий между входом в систему и просмотром списка карт. Первый сценарий для входа в систему:
public class AuthorizationTest {
@Rule
public ActivityTestRule<AuthorizationActivity> mActivityRule = new ActivityTestRule(AuthorizationActivity.class);
private Activity activity;
@Before()
public void setup() {
activityTestRule.launchActivity(new Intent());
activity = activityTestRule.getActivity();
}
@After()
public void tearDown() {
activityTestRule.finishActivity();
}
@Test
public void login() throws Exception {
onView(withId(R.id.btnAuthLogin)).perform(click());
onView(withId(R.id.etSessionKey1)).perform(typeText("1234"));
closeSoftKeyboard();
onView(isRoot()).perform(waitId(R.id.swipeRefreshLayout, 45000));
ViewInteraction viewInteraction = Espresso.onView(withText("**** 0431"));
viewInteraction.perform(click());
//asssert login success
onView(withId(R.id.toastloginsuccess)).check(matches(isDisplayed()));
}
Второй сценарий непосредственно в активности списка карт.
public class CardListTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
private Activity activity;
@Before()
public void setup() {
activityTestRule.launchActivity(new Intent());
activity = activityTestRule.getActivity();
}
@After()
public void tearDown() {
activityTestRule.finishActivity();
}
@Test
public void checkMoneyBackButton() throws Exception {
//assertMainActivity
onView(withId(R.id.menuTitle)).check(matches(isDisplayed()));
//Assert what you want
onView(withId(R.id.btnTransferToCard)).check(matches(isDisplayed()));
// Do what you want
}
Надеюсь на его помощь.