Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓浓缩咖啡vs Actionbar_Android_Testing_Android Espresso - Fatal编程技术网

Android 安卓浓缩咖啡vs Actionbar

Android 安卓浓缩咖啡vs Actionbar,android,testing,android-espresso,Android,Testing,Android Espresso,我一直在尝试测试一个应用程序,它有一个使用浓缩咖啡的菜单抽屉 现在来看看奇怪之处 在第一个测试中,我打开抽屉并单击一个项目,然后继续进行其余的测试。这一切都很好 当我添加第二个做完全相同事情的测试时,我得到一个异常。这似乎与菜单抽屉的内容有关,但我不知所措 例外情况如下: com.google.android.apps.common.testing.ui.espresso.PerformException: Error performing 'single click' on view '(wi

我一直在尝试测试一个应用程序,它有一个使用浓缩咖啡的菜单抽屉

现在来看看奇怪之处

在第一个测试中,我打开抽屉并单击一个项目,然后继续进行其余的测试。这一切都很好

当我添加第二个做完全相同事情的测试时,我得到一个异常。这似乎与菜单抽屉的内容有关,但我不知所措

例外情况如下:

com.google.android.apps.common.testing.ui.espresso.PerformException: Error performing 'single click' on view '(with id: is <2131099739> and with text: is "Events")'.
at com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.build(PerformException.java:67)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:57)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:146)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:77)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:69)
at com.xxx.app.events.StackOverflowExampleTest.selectMenu(StackOverflowExampleTest.java:83)
at com.xxx.app.events.StackOverflowExampleTest.setUp(StackOverflowExampleTest.java:72)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:177)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:119)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1608)
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
at least 90 percent of the view's area is displayed to the user.
Target view: "TextView{id=2131099739, res-name=menu_item_content, visibility=VISIBLE, width=432, height=112, 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=24.0, y=2.0, text=Events, input-type=0, ime-target=false}"
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$1.run(ViewInteraction.java:100)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
com.google.android.apps.common.testing.ui.espresso.PerformException:在视图上执行“单击”时出错(id为,文本为“事件”)。
位于com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.build(PerformException.java:67)
位于com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:57)
位于com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
在com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:146)上
位于com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:77)
在com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform上(ViewInteraction.java:69)
在com.xxx.app.events.StackOverflowExampleTest.selectMenu(StackOverflowExampleTest.java:83)上
位于com.xxx.app.events.StackOverflowExampleTest.setUp(StackOverflowExampleTest.java:72)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:192)上
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:177)中
位于android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
位于com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:119)
位于android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1608)
原因:java.lang.RuntimeException:将不执行操作,因为目标视图与以下一个或多个约束不匹配:
至少90%的视图区域显示给用户。
目标视图:“文本视图”{id=21301099739,res name=menu_item_content,visibility=VISIBLE,width=432,height=112,has focus=false,has focusable=false,has window focus=true,is clickable=false,is enabled=true,is focusable=false,is layout requested=false,is selected=false,root is layout requested=false,has input connection=false,x=24.0,y=2.0,text=事件,输入类型=0,输入法目标=false}”
在com.google.android.apps.common.testing.ui.espresso.ViewInteraction$1.run上(ViewInteraction.java:100)
位于java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
位于java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
位于java.util.concurrent.FutureTask.run(FutureTask.java:137)
位于android.os.Handler.handleCallback(Handler.java:615)
位于android.os.Handler.dispatchMessage(Handler.java:92)
位于android.os.Looper.loop(Looper.java:137)
位于android.app.ActivityThread.main(ActivityThread.java:4898)
位于java.lang.reflect.Method.Invokenactive(本机方法)
在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)上
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
在dalvik.system.NativeStart.main(本机方法)
这是测试课

public class StackOverflowExampleTest extends ActivityInstrumentationTestCase2<MainActivity_>
{
    public StackOverflowExampleTest()
    {
        super(MainActivity_.class);
    }

    /**
     * Basic check for content displayed
     */
    @SuppressWarnings("unchecked")
    public void testSanityCheck()
    {
        // check title is shown
        onView(allOf(withId(R.id.event_view_title), isDisplayed())).check(
                        matches(withText("Isaac Vladimir Sinead Stacey"))); //$NON-NLS-1$

        // check content is shown
        onView(allOf(withId(R.id.event_view_text), isDisplayed())).check(
                        matches(withText(startsWith("Arcu ipsumcurabitur. Aliquammauris sodalessed arcu.")))); //$NON-NLS-1$

        // check "more details" is shown
        onView(allOf(withId(R.id.event_view_link), isDisplayed()))
                        .check(matches(withText(R.string.events_button_text)));
    }

    /**
     * Basic check for content displayed
     */
    @SuppressWarnings("unchecked")
    public void testSanityCheck2()
    {
        // check title is shown
        onView(allOf(withId(R.id.event_view_title), isDisplayed())).check(
                        matches(withText("Isaac Vladimir Sinead Stacey"))); //$NON-NLS-1$

        // check content is shown
        onView(allOf(withId(R.id.event_view_text), isDisplayed())).check(
                        matches(withText(startsWith("Arcu ipsumcurabitur. Aliquammauris sodalessed arcu.")))); //$NON-NLS-1$

        // check "more details" is shown
        onView(allOf(withId(R.id.event_view_link), isDisplayed()))
                        .check(matches(withText(R.string.events_button_text)));
    }

    @Override
    protected void setUp() throws Exception
    {
        super.setUp();

        // start the activity
        this.getActivity();

        // show events fragment
        this.selectMenu(R.string.menu_item_events);
    }

    @SuppressWarnings("unchecked")
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    protected void selectMenu(final int menuItemResId)
    {
        // open the drawer
        onView(withId(android.R.id.home)).perform(click());

        // click the supplied menu item (aka list item)
        onView(allOf(withId(R.id.menu_item_content), withText(this.getActivity().getString(menuItemResId)))).perform(
                        click());

    }
}
公共类StackOverflowExampleTest扩展了ActivityInstrumentationTestCase2
{
公共StackOverflowExampleTest()
{
超级(主要活动类);
}
/**
*显示内容的基本检查
*/
@抑制警告(“未选中”)
公共void testSanityCheck()
{
//显示检查标题
onView(allOf(带id(R.id.event\u view\u title),isDisplayed())。检查(
匹配(带文本(“Isaac Vladimir Sinead Stacey”);//$NON-NLS-1$
//显示检查内容
onView(allOf(带id(R.id.event\u view\u text),isDisplayed())。检查(
匹配(使用文本(开始使用(“Arcu ipsumcurabitur.Aliquammauris sodalessed Arcu”));/$NON-NLS-1$
//选中显示的“更多详细信息”
onView(allOf(带id(R.id.event\u view\u link),isDisplayed())
.检查(匹配(使用文本(R.string.events\u button\u text));
}
/**
*显示内容的基本检查
*/
@抑制警告(“未选中”)
公共无效testSanityCheck2()
{
//显示检查标题
onView(allOf(带id(R.id.event\u view\u title),isDisplayed())。检查(
匹配(带文本(“Isaac Vladimir Sinead Stacey”);//$NON-NLS-1$
//显示检查内容
onView(allOf(带id(R.id.event\u view\u text),isDisplayed())。检查(
匹配(使用文本(开始使用(“Arcu ipsumcurabitur.Aliquammauris sodalessed Arcu”));/$NON-NLS-1$
//选中显示的“更多详细信息”
onView(allOf(带id(R.id.event\u view\u link),isDisplayed())
.检查(匹配(使用文本(R.string.events\u button\u text));
}
@凌驾
受保护的void setUp()引发异常
{
super.setUp();
//开始活动
这个.getActivity();
//显示事件片段
选择菜单(R.string.menu\u项\u事件);
}
@抑制警告(“未选中”)
@TargetApi(构建版本代码蜂窝)
受保护的无效选择菜单(最终整数菜单)
{
//打开抽屉
onView(withId(android.R.id.home)).perform(click());
//单击提供的菜单项(又名列表项)
onView(allOf(withId(R.id.menu\u item\u content),withText(this.getActivity().getString(menuItemResId)))。执行(
单击());
}
}

抽屉中的视图似乎还不可见。在对其执行任何操作之前,您可以尝试断言视图的可见性:

assertTrue(withEffectiveVisibility(Visibility.VISIBLE).matches(myView));
assertFalse(withEffectiveVisibility(Visibility.VISIBLE).matches(myView));

当您要操作的视图不可见时,我遇到了相同的问题
onView(withId(is(R.id.button_login))).perform(
    scrollTo(), 
    click());
onData(is(instanceOf(com.your.package.SomeDrawerItem.class)))
    .inAdapterView(withId(R.id.drawer_listview))
    .atPosition(itemPositionInDrawer).perform(click());