osama-raddad / android-test-kit

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

java.lang.RuntimeException: No activities found if calling check right after getActivity when test starts #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. In the very first step of the test, call getActivity()
2. Call something like onView(withId(xxx)).check(matches(xxx)) right in the 
next line
3. Sometimes the following error happens:
java.lang.RuntimeException: No activities found. Did you forget to launch the 
activity by calling getActivity() or startActivitySync or similar? 

What is the expected output? What do you see instead?
The error does not happen. The check is executed when the activity finishes its 
lifecycle to an idle state

What version of the product are you using? On what operating system?
On Android 4.1.2 tablet (Samsung Galaxy Note 10.1) and emulators

Please provide any additional information below.

Original issue reported on code.google.com by K76...@gmail.com on 18 Dec 2013 at 6:31

GoogleCodeExporter commented 9 years ago
I think there's a problem in this code, because this is where the exception was 
thrown
RootViewPicker

  private void waitForAtLeastOneActivityToBeResumed() {
    Collection<Activity> resumedActivities =
        activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.isEmpty()) {
      uiController.loopMainThreadUntilIdle();
      resumedActivities = activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED);
    }
    if (resumedActivities.isEmpty()) {
      List<Activity> activities = Lists.newArrayList();
      for (Stage s : EnumSet.range(Stage.PRE_ON_CREATE, Stage.RESTARTED)) {
        activities.addAll(activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED));
      }
      if (activities.isEmpty()) {
        throw new RuntimeException("No activities found. Did you forget to launch the activity "
            + "by calling getActivity() or startActivitySync or similar?");
      }

When there's no activity in resumed state, it tries to find all activities in 
other states. However, when calling to the activitymonitor, it still passes 
Stage.RESUME in. It should be:
      for (Stage s : EnumSet.range(Stage.PRE_ON_CREATE, Stage.RESTARTED)) {
        activities.addAll(activityLifecycleMonitor.getActivitiesInStage(s));
      }

Original comment by K76...@gmail.com on 19 Dec 2013 at 6:22

GoogleCodeExporter commented 9 years ago
There's another problem in the method:

      for (int waitIdx = 0; waitIdx < waitTimes.length; waitIdx++) {
        Log.w(TAG, "No activity currently resumed - waiting: " + waitTimes[waitIdx]
            + "ms for one to appear.");
        uiController.loopMainThreadForAtLeast(waitTimes[waitIdx]);
        resumedActivities = activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED);
        if (!resumedActivities.isEmpty()) {
          break;
        }
      }
      throw new RuntimeException("No activities in stage RESUMED. Did you forget to launch the "
          + "activity. (test.getActivity() or similar)?");

Even if it gets the resumed activities in the for loop, it will still throw the 
exception. It should be 

if(resumedActivities.isEmpty())
{
      throw new RuntimeException("No activities in stage RESUMED. Did you forget to launch the "
          + "activity. (test.getActivity() or similar)?");
}

Original comment by K76...@gmail.com on 29 Dec 2013 at 11:32

GoogleCodeExporter commented 9 years ago
Thanks for reporting. Will be fixed in the next release.

Original comment by vale...@google.com on 2 Jan 2014 at 9:22

GoogleCodeExporter commented 9 years ago
Fixed in 1.1

Original comment by vale...@google.com on 9 Jan 2014 at 7:34

GoogleCodeExporter commented 9 years ago
Using 1.1 but still having this issue

Original comment by marconi....@gmail.com on 9 Mar 2014 at 4:01

GoogleCodeExporter commented 9 years ago
Same here, this is still a problem

Original comment by kot...@gmail.com on 8 Jan 2015 at 7:47

GoogleCodeExporter commented 9 years ago
I confirm that the issue still occurs on Espresso 2.0. Marking this as FIXED 
seems premature to me.

Original comment by morawski...@gmail.com on 31 Jan 2015 at 10:53

GoogleCodeExporter commented 9 years ago
getActivity() cause app crash.

it mention about attempt to invoke virtual method.

Original comment by jasonars...@gmail.com on 18 Feb 2015 at 2:56