espresso onView的性能不一致 [英] espresso onView inconsistent performance

查看:97
本文介绍了espresso onView的性能不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Junit4和Espresso进行测试.我在使用浓缩咖啡测试时遇到了一个奇怪的问题-当我调用onView时,有时一切都按预期执行,但是有时我的测试死机了,在60秒后,我得到类似"android.support.test.espresso.AppNotIdleException:循环在60秒内进行了63次迭代.以下空闲条件失败ASYNC_TASKS_HAVE_IDLED 例如:

I am using Junit4 and Espresso for my tests. I am facing a weird issue with espresso tests - when I call onView sometimes everything is executed like it is supposed to, but sometimes my test freezes and after 60 seconds I get something like this "android.support.test.espresso.AppNotIdleException: Looped for 63 iterations over 60 SECONDS. The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED" For example :

    onView(withId(R.id.zone_button_continue)).perform(click());
    onView(withId(R.id.loginButton)).check(matches(isDisplayed()));
    onView(withId(R.id.number)).check(matches(isDisplayed()));
    onView(withId(R.id.password)).check(matches(isDisplayed()));
    onView(withId(R.id.number)).perform(typeText(phoneNumber));
    onView(withId(R.id.password)).perform(typeText(password));
    onView(withId(R.id.loginButton)).perform(click());

一切都正确执行,除了最后一行-出于某种原因,它找不到该loginButton,但是那里有100%的百分比.我能做

everything gets executed correctly, except the last line - for some reason it can't find that loginButton, but it is there 100% percent. I can do

activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            activity.findViewById(R.id.loginButton).performClick();
             }
    });

,并且有效.在我的大部分活动中,我都遇到类似的问题-有时onView有时无法正常工作.

and that works. I have similar problems throughout most of my activities - sometimes onView is working sometimes not.

是什么原因导致这种不一致?我一直在与这个问题作斗争一段时间,这使我的测试感到非常沮丧和困难.到目前为止,我的结论是我的gradle依赖项出了点问题,或者我的应用程序中存在某种错误,导致espresso无法正常工作.但是奇怪的是,在上面的示例中,使用onView的所有东西都在工作,除了最后一行,并且所有事情都在一个活动中发生,这使我怀疑该错误是否在我的应用程序内. 这是我的gradle依赖项:

What could cause such an inconsistency? I have been fighting with this issue for a while, and it makes my testing very frustrating and difficult. My conclusions this far is that something is wrong with my gradle dependencies or there is some kind of bug in my application that prevents espresso to work properly. But it is strange that in the example above everything with onView is working except last line and everything is happening in one activity and that makes me doubt that the bug is within my application. Here are my gradle dependencies:

compile files('src/main/libs/guice-3.0-no_aop.jar')
compile files('src/main/libs/javax.inject-1.jar')
compile files('src/main/libs/roboguice-2.0.jar')
compile files('src/main/libs/junit-4.11.jar')
compile files('src/main/libs/hamcrest-core-1.3.jar')
compile files('src/main/libs/GeoLib.jar')
compile files('src/main/libs/GeoPolygons.jar')
compile files('src/main/libs/universal-image-loader-1.9.4.jar')
compile files('src/main/libs/javax.annotation-3.2-b06-sources.jar')
compile ('uk.co.chrisjenx:calligraphy:2.1.0'){
    exclude group:'com.android.support'
}
compile 'com.squareup:otto:1.3.5'
compile ('com.google.android.gms:play-services:6.5.87'){
    exclude group:'com.android.support'
}
compile 'com.android.support:support-annotations:22.2.1'
compile ('com.android.support:appcompat-v7:22.2.0'){
    exclude group:'com.android.support'
}
compile ('com.android.support:support-v4:22.2.0'){
    exclude group:'com.android.support', module:'support-annotations'
}
compile ('com.android.support:palette-v7:22.2.0'){
    exclude group:'com.android.support'
}
compile 'com.google.code.findbugs:jsr305:2.0.1'

compile 'com.nineoldandroids:library:2.4.0'
compile 'pl.charmas.android:android-reactive-location:0.4@aar'
compile 'io.reactivex:rxjava:1.0.3'
compile files('src/main/libs/FlurryAnalytics-6.1.0.jar')
compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
//    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('com.android.support.test:runner:0.4.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to use JUnit 4 rules
androidTestCompile('com.android.support.test:rules:0.4.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
// Set this dependency to build and run Espresso tests
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}

androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.1') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.1') {
    // PackagingOptions modified to make this work
    exclude group: 'com.android.support', module: 'support-annotations'
}
testCompile 'junit:junit:4.11'
testCompile ('org.mockito:mockito-core:1.9.5'){
    exclude group: 'org.hamcrest'
}
compile 'org.mod4j.org.apache.commons:lang:2.1.0'

请帮助我解决这个问题,我完全没有想法,只能坚持下去.

Please help me with this problem, I am completely out of ideas and stuck with it.

推荐答案

查看为什么收到带有消息以下空闲条件失败的ASYNC_TASKS_HAVE_IDLED"的AppNotIdleException的最简单方法是:

The easiest way to see why you get an AppNotIdleExceptionwith the message "The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED", is to:

  • 在Android Studio中以调试模式运行测试
  • 等到测试挂起
  • (默认)60秒过去之前,请暂停测试
  • 在线程"列表中查看并查看名为"AsyncTask#1"的线程,依此类推.展开处于正在运行"状态的计算机.在那里,您将看到代码的哪一部分使应用程序保持忙碌状态

这是我的案例的结果,因此我不得不为测试禁用Facebook SDK,以使其再次稳定:

This was the result for my case, so I had to disable the Facebook SDK for my tests to make them stable again:

这篇关于espresso onView的性能不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆