gpt4 book ai didi

android - Espresso,点击位置上的一个项目

转载 作者:行者123 更新时间:2023-11-30 01:37:55 25 4
gpt4 key购买 nike

我试图点击 GridView 中特定位置的项目。

onData(instanceOf(MyClass.class))
.inAdapterView(withId(R.id.my_view))
.atPosition(R.integer.my_id)
.perform(click());

但我得到这个 java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

我正在使用 MockWebServer 对响应进行排队,即使在 UI 显示所有列表项之后,我仍然收到此错误,我不确定为什么。

另外,我想获取特定项目的内容。

最佳答案

好吧,我认为那是因为您匹配的只是一个类,而不是具有值的特定适配器。

请考虑这篇文章:

The matcher passed as argument to onData() must match the value as returned by Adapter.getItem(). So the first version doesn't match, because of the wrong type being used. It should be:

onData(is(instanceOf(IconRowAdapter.IconRow.class)))

What also can be a pitfall is using equalTo on different kinds of CharSequences. String is a CharSequence, but if IconRow.getText() returns CharSequence instead of String, then this can also be Spannable, Editable, etc in which case equalTo wouldn't match. So if IconRow.getText() return anything but String, make sure to convert it into a String before comparison.

这篇文章摘自How to use Espresso to test item in adapter at a specific position

你的问题缺少测试类的代码,所以我不能直接给你答案。我只能推荐阅读上面的 StackOverflow 链接。

希望对你有帮助

关于android - Espresso,点击位置上的一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34886561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com