In Android Studio, in the androidTest folder, I have this test case:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginActivityTest {
@Rule
public ActivityTestRule<LoginActivity> activityTestRule =
new ActivityTestRule<>(LoginActivity.class);
@Test
public void teamsListIsSortedAlphabetically() {
onView(withId(R.id.etEmail)).perform(click(), replaceText("[email protected]")
);
onView(withId(R.id.etPassword)).perform(click(), replaceText("asdasd")
);
onView(withId(R.id.bLoginSubmit)).perform(click());
}
}
The app launches LoginActivity, logs in, the next activity is shown for 1-2 seconds and then it exits the activity leaving me on the launcher screen. How do I make Espresso stay on that screen?
perform(pressBack()); this must dismiss your dialog. perform() requires a ViewAction and Espresso. pressBack() returns void . Would you like to add more details?
The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app.
Espresso tests state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way. Espresso tests run optimally fast!
Validate intentsUsing the intended() method, which is similar to Mockito. verify() , you can assert that a given intent has been seen. However, Espresso-Intents doesn't stub out responses to intents unless you explicitly configure it to do so. // User action that results in an external "phone" activity being launched.
Sorry, but it's impossible.
Please read this Google reference: Automating User Interface Tests
Espresso, Robotium, Calabash and other UI test frameworks were made for short interaction testing events. It simulates an user's specific behavior - run app, do some tricks and (if successful) than close an app.
Of course, Espresso allow you to create custom idling resources and than register it in app.
The simplest way to hibernate a test for a specific amount of time is use method Thread.sleep(time_in_miliseconds)
, but like I said it's against idea of automated testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With