suli1 / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

Espresso.pressBack() sometimes throw "Pressed back and killed the app" while it actually didn't #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Write Espresso.pressBack() on the activity where pressing back once doesn't 
exit the app.

What is the expected output? What do you see instead?
Expected: The app does what it is expected to do when back is pressed
Actual: 
com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException: 
Pressed back and killed the app

What version of the product are you using? On what operating system?
Espresso 1.1

Please provide any additional information below.
This is a very rare problem, but it happens. I know know how UiController 
handles activity lifecycle, but it seems like it doesn't wait until activity to 
be resumed to continue. As a result, the following codes at the end of 
pressBack() can sometimes get no activity, because it's in the middle of 
switching activity:

    if (this.key.getKeyCode() == KeyEvent.KEYCODE_BACK) {
      controller.loopMainThreadUntilIdle();
      boolean activeActivities = !ActivityLifecycleMonitorRegistry.getInstance()
          .getActivitiesInStage(Stage.RESUMED)
          .isEmpty();
      if (!activeActivities) {
        Throwable cause = new PerformException.Builder()
          .withActionDescription(this.getDescription())
          .withViewDescription(HumanReadables.describe(view))
          .build();
        throw new NoActivityResumedException("Pressed back and killed the app", cause);
      }
    }

I checked my error log and found that it calls 
getActivitiesInStage(Stage.RESUMED) when my previous activity is in pause and 
the next activity which should show up after the back was still on its way to 
resumed.

Original issue reported on code.google.com by K76...@gmail.com on 17 Jan 2014 at 5:53

GoogleCodeExporter commented 9 years ago

Original comment by vale...@google.com on 7 May 2014 at 4:44

GoogleCodeExporter commented 9 years ago
This was not a dupe of #55.

This has been fixed internally - targeted for Espresso 1.2 publicly

Original comment by thoma...@google.com on 8 Oct 2014 at 8:43