osama-raddad / android-test-kit

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

'is drawer closed' does not match the selected view. #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create Activity with DrawerLayout
2. Create Activity layout,

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="310dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:divider="#00000000"
        android:dividerHeight="0dip"
        android:clickable="true"
        android:fadeScrollbars="false"
        android:background="#f3f3f4"
        android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>

3. In test method,

openDrawer(R.id.drawer_layout);
onView(withId(R.id.drawer_layout)).check(matches(isOpen()));
onData(allOf(is(instanceOf(String.class)), 
is("Text"))).inAdapterView(withId(R.id.left_drawer)).perform(click());
onView(withId(R.id.drawer_layout)).check(matches(isClosed()));

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

Expected the assertion to pass on isOpen and isClosed or fail on isOpen. 
Instead, isOpen passes, perform(click()) raises no exceptions, and isClosed 
raised this error:

com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler$As
sertionFailedWithCauseError: 'is drawer closed' doesn't match the selected view.
Expected: is drawer closed
Got: "DrawerLayout{id=2131230815, res-name=drawer_layout, visibility=VISIBLE, 
width=768, height=1038, has-focus=true, has-focusable=true, 
has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=true, 
is-focusable=true, is-layout-requested=false, is-selected=false, 
root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, 
child-count=2}"

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:579)
at 
com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.ge
tUserFriendlyError(DefaultFailureHandler.java:69)
at 
com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.ha
ndle(DefaultFailureHandler.java:40)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronou
slyOnUiThread(ViewInteraction.java:159)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.check(ViewInt
eraction.java:133)
at <package>.test.BaseUiTest.selectDrawerItem(BaseUiTest.java:110)
at <package>.test.BaseUiTest.testNavigationDrawer(BaseUiTest.java:115)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at 
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at 
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTes
tCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at 
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:55
4)
at 
com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunne
r.onStart(GoogleInstrumentationTestRunner.java:167)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Caused by: junit.framework.AssertionFailedError: 'is drawer closed' doesn't 
match the selected view.
Expected: is drawer closed
Got: "DrawerLayout{id=2131230815, res-name=drawer_layout, visibility=VISIBLE, 
width=768, height=1038, has-focus=true, has-focusable=true, 
has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=true, 
is-focusable=true, is-layout-requested=false, is-selected=false, 
root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, 
child-count=2}"

at 
com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.assertTh
at(ViewMatchers.java:789)
at 
com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions$2.ch
eck(ViewAssertions.java:76)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction$2.run(ViewInt
eraction.java:145)
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:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4998)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
at dalvik.system.NativeStart.main(Native Method)

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

Using "espresso-contrib-1.1-bundled.jar". Running test in Intel Atom (x86)  w/ 
Intel HAXM emulator with Android 4.4.2 (API 19) on a Macbook Pro Retina OS X 
version 10.9.2.

Please provide any additional information below.

IDE is Android Studio.

Original issue reported on code.google.com by matthew....@gmail.com on 28 Feb 2014 at 5:29

GoogleCodeExporter commented 9 years ago
Running the test,

openDrawer(R.id.drawer_layout);
onView(withId(R.id.drawer_layout)).check(matches(isOpen()));
closeDrawer(R.id.drawer_layout);
onView(withId(R.id.drawer_layout)).check(matches(isClosed()));

passes. It could be my implementation of onData....

Original comment by matthew....@gmail.com on 28 Feb 2014 at 11:04

GoogleCodeExporter commented 9 years ago
also, using

onView(withId(R.id.drawer_layout)).check(doesNotExist());

passes. It's probably my mistake, but when certain drawer items are clicked and 
the drawer is fully closed, I show an AlertDialog. When this happens, the 
drawer's layout doesn't exist. When the dialog is not shown, the layout does 
exist.

Original comment by matthew....@gmail.com on 28 Feb 2014 at 11:39

GoogleCodeExporter commented 9 years ago

Original comment by vale...@google.com on 6 May 2014 at 11:56

GoogleCodeExporter commented 9 years ago
Did you find out what was wrong with your onData implementation...im having the 
same problem myself.

Original comment by tbola...@gmail.com on 25 Sep 2014 at 7:02