Android:Espresso

时间:2017-01-02 07:12:42

标签: android android-espresso

我在我的应用中使用两个导航视图,第二个(右)一个是通过自定义组件。它在手动测试期间工作正常,但浓咖啡在测试期间无法识别。第二个NAV保持不可见,并在相应方法的创建方法上激活它。

我尝试使用相同的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(Bundle savedInstanceState)方法中的代码方法使其可见 drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, navigationViewRight);

// Espresso测试方法

@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失败日志

01-02 12:25:58.228 18570-18585 /? I / TestRunner:android.support.test.espresso.PerformException:执行&#39;单击带有id&#39;的菜单项时出错在视图&#39;上使用id:com.example.tt0401:id / nav_right_view&#39;。                                                    在android.support.test.espresso.PerformException $ Builder.build(PerformException.java:83)                                                    在android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80)                                                    在android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)                                                    在android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)                                                    在android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)                                                    在android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)                                                    在com.example.tt0401.RecordActivity3Test.navigationDrawer(RecordActivity3Test.java:135)                                                    at java.lang.reflect.Method.invoke(Native Method)                                                    在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)                                                    在android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)                                                    在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)                                                    在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)                                                    在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)                                                    在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)                                                    在org.junit.runners.ParentRunner.run(ParentRunner.java:363)                                                    在org.junit.runners.Suite.runChild(Suite.java:128)                                                    在org.junit.runners.Suite.runChild(Suite.java:27)                                                    在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)                                                    在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)                                                    在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)                                                    在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)                                                    在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)                                                    在org.junit.runners.ParentRunner.run(ParentRunner.java:363)                                                    在org.junit.runner.JUnitCore.run(JUnitCore.java:137)                                                    在org.junit.runner.JUnitCore.run(JUnitCore.java:115)                                                    在android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)                                                    在android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)                                                    在android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1932)                                                 引发者:java.lang.RuntimeException:由于目标视图与以下一个或多个约束不匹配,因此不会执行操作:                                                (可从类中分配:类android.support.design.widget.NavigationView和视图具有有效可见性= VISIBLE,并且至少90%的视图区域将显示给用户。)                                                目标视图:&#34; 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}&#34;                                                    在android.support.test.espresso.ViewInteraction $ 1.run(ViewInteraction.java:138)                                                    at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:428)                                                    在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                 在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 个答案:

答案 0 :(得分:0)

请尝试使其隐身,而不是进入<com.example.tt0401.NavigationViewRight>

  android:visibility="gone"