HeyCFarmer / 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

GoogleCodeExporter commented 9 years ago
Still having this issue. Is there a workaround ?

java.lang.RuntimeException: No activities found. Did you forget to launch the 
activity by calling getActivity() or startActivitySync or similar?
at 
android.support.test.espresso.base.RootViewPicker.waitForAtLeastOneActivityToBeR
esumed(RootViewPicker.java:189)
at 
android.support.test.espresso.base.RootViewPicker.findRoot(RootViewPicker.java:1
34)
at android.support.test.espresso.base.RootViewPicker.get(RootViewPicker.java:80)
at 
android.support.test.espresso.ViewInteractionModule.provideRootView(ViewInteract
ionModule.java:69)
at 
android.support.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(V
iewInteractionModule_ProvideRootViewFactory.java:23)
at 
android.support.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(V
iewInteractionModule_ProvideRootViewFactory.java:9)
at 
android.support.test.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:68
)
at android.support.test.espresso.ViewInteraction$2.run(ViewInteraction.java:166)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Original comment by ali....@gmail.com on 16 Jul 2015 at 4:44