eduyubero / android-test-kit

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

Changing activity and the calling onView failed #48

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Press the up button on the activity bar.
onView(Matchers.allOf(
                withContentDescription("Navigate up"),
                isDisplayed(),
                Matchers.not(
                        ViewMatchers.hasDescendant(
                                withContentDescription("Navigate up")
                        )
                )))..perform(click());

2. Wait for the root activity of the view to show.
onView(withId(viewId)).check(matches(isDisplayed()));.

What is the expected output? What do you see instead?

Sometimes the code works, sometime it does not.
java.lang.RuntimeException: No activities found. Did you forget to launch the 
activity by calling getActivity() or startActivitySync or similar?
at 
com.google.android.apps.common.testing.ui.espresso.base.RootViewPicker.waitForAt
LeastOneActivityToBeResumed(RootViewPicker.java:164)
at 
com.google.android.apps.common.testing.ui.espresso.base.RootViewPicker.findRoot(
RootViewPicker.java:109)
at 
com.google.android.apps.common.testing.ui.espresso.base.RootViewPicker.get(RootV
iewPicker.java:65)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule.provide
RootView(ViewInteractionModule.java:51)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule$$Module
Adapter$ProvideRootViewProvidesAdapter.get(ViewInteractionModule$$ModuleAdapter.
java:187)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule$$Module
Adapter$ProvideRootViewProvidesAdapter.get(ViewInteractionModule$$ModuleAdapter.
java:151)
at 
com.google.android.apps.common.testing.ui.espresso.base.ViewFinderImpl.getView(V
iewFinderImpl.java:52)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction$2.run(ViewInt
eraction.java:141)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)

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

espresso-1.1
Mac OS X 10.9.1:
-- Emulator Google API's 4.4 API 19 7.68 x 1020
-- GennyMotion 2.03 (gennymotion.com) with WXGA tablet 10.1 4.2.2 API 17.

The problem did not occur as often with espresso-1.0

Workaround:

    public static void waitForView(int viewId) {
        long startTime = (new Date()).getTime();
        long endTime = startTime + 15000;
        do {
            try {
                onView(withId(viewId)).check(matches(isDisplayed()));
                return;
            } catch(Throwable ex) {
                Log.d(TAG,  "trying again waiting for view "
                        + viewId + " " + ex);
                Thread.yield();
            }
        } while (((new Date()).getTime()) < endTime);
      onView(withId(viewId)).check(matches(isDisplayed()));
    }

Use the resource id of the view that matches the outermost layout of the 
activities view.

Maybe similar to issue #33

Original issue reported on code.google.com by marcp...@gmail.com on 17 Jan 2014 at 2:16

GoogleCodeExporter commented 9 years ago

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