2017-01-02 44 views
1

我在我的應用程序中使用了兩個導航視圖,第二個(右)一個是通過自定義組件。它在手動測試過程中工作正常,但濃咖啡在測試過程中無法識別。第二個NAV保持不可見狀態,並在相應方法的創建方法中激活它。Android:第二個導航視圖不被Espresso識別

我試圖使用相同appraoch來測試第一導航視圖,它工作正常..

下面是相關的代碼段和原木

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
    android:id="@+id/nav_left_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

    <com.example.tt0401.NavigationViewRight 
    android:id="@+id/nav_right_view" 
    android:layout_width="wrap_content" 
    android:layout_height="600dp" 
    android:layout_marginTop="80dp" 
    android:layout_gravity="end" 
    android:fitsSystemWindows="true" 
    android:visibility="gone" 
    app:itemBackground="@drawable/nav_item_selector" 
    app:headerLayout="@layout/nav_header_right" 
    app:menu="@menu/activity_right_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

//代碼內的onCreate(捆綁savedInstanceState)方法的方法使其可見 drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, navigationViewRight);

//咖啡試驗方法

@Test 
public void navigationDrawer() throws Exception { 
fabAddClick(); 
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.END)); 
onView(withId(R.id.nav_right_view)).perform(NavigationViewActions.navigateTo(1000003)); 
} 

Espresso Failure Logs

01-02 12:25:58.228 18570-18585 /?我/ TestRunner:android.support.test.espresso.PerformException:錯誤執行'點擊菜單項與ID'視圖'與id:com.example.tt0401:id/nav_right_view'。 at android.support.test.espresso.PerformException $ Builder.build(PerformException.java:83) at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80) at android.support。 test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56) at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184) at android.support.test.espresso.ViewInteraction.doPerform( ViewInteraction.java:115) at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87) at com.example.tt0401.RecordActivity3Test.navigationDrawer(RecordActivity3Test.java:135) 在java.lang.reflect.Method.invoke(本機方法) 在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50) 在org.junit.internal.runners.model.ReflectiveCallable.run (ReflectiveCallable.java:12) 在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55) at android.support.test .rule.ActivityTestRule $ ActivityStatement.evaluate(ActivityTestRule.java:270) 在org.junit.rules.RunRules.evaluate(RunRules.java:20) 在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner。的java:78) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290) 在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58) at org .junit.runners.ParentRunner $ 2.evaluate(ParentRunne r.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit。runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access $ 000(ParentRunner .java:58) at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner。 JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) at android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1932) 引起:java.lang.RuntimeException:將不會執行操作,因爲目標視圖不符合以下一個或多個約束: (可從類android android.permission.WEB命名中指定。 support.design.widget.NavigationView和view具有有效的可見性= VISIBLE,並且至少有90%的視圖區域顯示給用戶。) 目標視圖:「NavigationViewRight {id = 2131624075,res-name = nav_right_view,visibility = INVISIBLE ,width = 980,height = 2100,has-focus = false,has-focusable = false ,has-window-focus = true,is-clickable = false,is-enabled = true,is-focused = false,is-focusable = false,is-layout-requested = false,is-selected = false,root-is -layout-requested = false,has-input-connection = false,x = 1440.0,y = 0.0,child-count = 1}「 at android.support.test.espresso.ViewInteraction $ 1.run(ViewInteraction.java:138 ) at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at androi 01-02 12:25: 58.228 18570-18585 /? I/TestRunner:-----結束異常----- 01-02 12:25:58.231 18570-18585 /? I/TestRunner:已完成:navigationDrawer(com.example.tt0401.RecordActivity3Test) 01-02 12:25:58.250 18570-18585 /? I/TestRunner的:運行完成:1次的測試中,1失敗,0忽略

回答

1

請儘量讓這種無形的,而不是去裏面<com.example.tt0401.NavigationViewRight>

android:visibility="gone" 
相關問題