0

Scenario:

  1. The user starts the app
  2. The user goes to the "CreateAccountActivity"
  3. In order to use the application the user has to enter the email and a password
  4. The user clicks "create" which switches to the next activity.

    @Test
    public void createAccountAndLogIn() {
        onView(withId(R.id.login_create)).perform(click());
        onView(withId(R.id.create_email)).perform(clearText(),typeText("xxx@gmail.com"));
        onView(withId(R.id.create_pass)).perform(clearText(),typeText("pass"));
        onView(withId(R.id.create_pass_repeat)).perform(clearText(),typeText("pass"));
        onView(withId(R.id.create_create_button)).perform(click());
    }
    

How to check, after the last line, if the new "MainActivity" was launched?

Michał
  • 616
  • 1
  • 7
  • 22

3 Answers3

0

You can control this defining a variable in Application class. When you define a variable in Application class , variable be protected until your app kill and you can reach this variable every class in project. I think it resolves your problem.

Kadir altınok
  • 230
  • 2
  • 5
  • You're right, but it is more like a "hack" than "solution". I was wondering if espresso supports this case. – Michał Feb 02 '16 at 14:50
0

Have you tried using onResume() method as a quick hack in your MainActivity? Have a boolean variable which changes to true in onResume() and false in onPause().

Cheers, SSG

SSG
  • 192
  • 2
  • 12
  • I like to test it in a "blackbox" way - you're probably right, but this will not do the job for me. – Michał Feb 02 '16 at 14:51
0

It is possible using ActivityLifecycleMonitor ... However it will not be a "black box" approach that you are looking for.

If you want to go full black box, asserting the view on the next activity should be sufficient enough to pass a test.

Here is the same question that has more detailed explanation.

Is there any way to know if an activity has been started with Espresso?

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