android.support.test.espresso.PerformException:在视图上执行“加载适配器数据"时出错 [英] android.support.test.espresso.PerformException: Error performing 'load adapter data' on view

查看:261
本文介绍了android.support.test.espresso.PerformException:在视图上执行“加载适配器数据"时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Espresso测试在搜索项目(例如自动完成)时出现的列表视图.除非用户在SearchView中输入了某些内容,否则列表视图不会出现.即,仅当用户在SearchView中输入内容时,我才将ListView设置为View.VISIBLE

当我尝试在列表视图中单击文本时出现此错误. android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id:'.使用onData无效.

添加人为的延迟是可行的,但是我不确定这是否是不好的做法,因为这似乎违背了onData等方法的目的.

我尝试过的事情:

我的代码

此代码有效,但我希望不必引入人为延迟.

public pickSuggestion(int index){

    /** artificial delay to allow list to appear. 
    This works but I shouldn't have to do this right? **/

    SystemClock.sleep(1000);

    onData(anything())
        .inAdapterView(withId(R.id.list))
        .atPosition(index)
        .onChildView(withId(R.id.mTextView))
        .perform(click());
}

解决方案

添加人为延迟有效,但是我不确定这是否不好 练习,因为它似乎破坏了诸如 onData等.

您的error具有Espresso限制.该框架需要在UI线程上运行,并且等待"直到它空闲为止.它不等待加载适配器数据,而是等待获取空闲资源

检查: http://dev.jimdo.com/2014/05/09/wait-for-it-a-deep-dive-into-espresso-s-idling-resources/

IdlingResource参考: https://developer.android. com/reference/android/support/test/espresso/IdlingResource.html

IdlingResource文档: https: //google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html

CountingIdlingResource: https://developer.android .com/reference/android/support/test/espresso/idling/CountingIdlingResource.html

SystemClock.sleep(1000)Thread.sleep(1000)这样的代码是不好的做法,因为更好的设备不需要那么多的时间,而较旧的设备则需要更多的时间,因此您的代码可能比较不稳定,而不是快速灵活.

解决方案是创建自己的Espresso IdlingResource来告诉Espresso何时可以执行测试而不会丢失数据和时间.

希望这会有所帮助.

I am using Espresso to test a list view that appears when I am searching for an item (like an autocomplete). The list view does not appear until the user has typed in something into the SearchView. i.e. I set the ListView to View.VISIBLE only when the user has typed something into the SearchView

I am getting this error when I try to click on text in a list view. android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id:'. Using onData did not work.

Adding an artificial delay works, but I am unsure if this is bad practice since it seems to defeat the purpose of methods such as onData etc.

What I've tried:

My Code

This code works, but I would prefer not to have to introduce an artificial delay.

public pickSuggestion(int index){

    /** artificial delay to allow list to appear. 
    This works but I shouldn't have to do this right? **/

    SystemClock.sleep(1000);

    onData(anything())
        .inAdapterView(withId(R.id.list))
        .atPosition(index)
        .onChildView(withId(R.id.mTextView))
        .perform(click());
}

解决方案

Adding an artificial delay works, but I am unsure if this is bad practice since it seems to defeat the purpose of methods such as onData etc.

Your error is provided with Espresso limitation. This framework need to run on UI thread and it 'waits' until it would be idle. It doesn't wait for loading adapter data, but waits for get idling resource

Check: http://dev.jimdo.com/2014/05/09/wait-for-it-a-deep-dive-into-espresso-s-idling-resources/

IdlingResource Reference: https://developer.android.com/reference/android/support/test/espresso/IdlingResource.html

IdlingResource Documentation: https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html

CountingIdlingResource: https://developer.android.com/reference/android/support/test/espresso/idling/CountingIdlingResource.html

Code like SystemClock.sleep(1000) or Thread.sleep(1000) is a bad practice because better devices don't need this amount of time and older ones need more, so your code maybe flaky, rather than fast and flexible.

The solution is to create your own Espresso IdlingResource to tell Espresso when it can perform tests without losing data and time.

Hope this will help.

这篇关于android.support.test.espresso.PerformException:在视图上执行“加载适配器数据"时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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