简体   繁体   English

Android Espresso 测试在物理设备上失败(PerformException)

[英]Android Espresso test failed on physical device (PerformException)

Hi, so I have this app that has this RecipeActivity with a recyclerview inside. 嗨,所以我有这个应用程序,里面有这个 RecipeActivity 和一个 recyclerview。

When you click a list item, it opens up another activity, passing an extra in the intent.当您单击一个列表项时,它会打开另一个活动,并在意图中传递一个额外的内容。

I just wanna test that simple functionality with Espresso (i'm starting with it). 我只想用 Espresso 测试这个简单的功能(我从它开始)。 This is my code: 这是我的代码:
.perform(RecyclerViewActions.scrollToPosition(0))

Now, the weird thing is that it passes when I run it on the Nexus 5.0 (Android 7.0) emulator (i've tried twice to be sure).现在,奇怪的是当我在Nexus 5.0 (Android 7.0) 模拟器上运行它时它通过了(我已经尝试过两次以确保)。

When I try it on my Oneplus 3 (with Android 7.1.1) (or even in another emulator with the same api level as the Nexus 5.0), it doesn't.当我在我的Oneplus 3(使用 Android 7.1.1) (或什至在另一个与 Nexus 5.0 具有相同 api 级别的模拟器中尝试它时,它没有。 This is the error message:这是错误消息:

 android.support.test.espresso.PerformException: Error performing 'android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction@3d98130' on view 'with id: com.onval.bakingapp:id/recipes_recyclerview'. at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83) at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80) at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56) at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184) at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115) at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87) at com.onval.bakingapp.ShowIngredientsTest.checkIfIngredientsAreShows(ShowIngredientsTest.java:34) at java.lang.reflect.Method.invoke(Native Method) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55) at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2110) Caused by: java.lang.IllegalStateException: No view holder at position: 0 at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.perform(RecyclerViewActions.java:290) at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6321) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Tests ran to completion.

What could it be?会是什么呢? Why is it not able to perform the action at position 0 when the emulator can?当模拟器可以执行位置 0 时,为什么它不能执行操作? Why does it say that viewholder doesn't exist in that position when it clearly does?为什么在明确存在的情况下说该位置不存在该查看者? The emulator doesn't have that issue!模拟器没有这个问题!

My only idea would be that the physical device is faster, and it checks before the viewholder is created...I tried to add a 我唯一的想法是物理设备速度更快,并且在创建查看器之前进行检查......我尝试添加一个
.perform(RecyclerViewActions.scrollToPosition(0))

in between the onView and the actionOnItemAtPosition, but it doesn't work anyway.在 onView 和 actionOnItemAtPosition 之间,但无论如何它都不起作用。

What am I missing? 我错过了什么? Thank you in advance! 先感谢您!

好的,我解决了,我需要使用 IdlingResources。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 浓缩咖啡:PerformException - Android Espresso: PerformException 无法解决:com.android.support.test.espresso:espresso-intents:27.0.2 - Failed to resolve: com.android.support.test.espresso:espresso-intents:27.0.2 Android Espresso UI测试-测试运行失败:由于“ java.lang.IllegalAccessError”,检测运行失败 - Android Espresso UI test - Test running failed: Instrumentation run failed due to 'java.lang.IllegalAccessError' 生成的Android espresso 测试运行失败,AndroidJUnitRunner 解析失败:Landroidx/test/platform/io/FileTestStorage; - Generated Android espresso test fails to run, AndroidJUnitRunner failed to resolve: Landroidx/test/platform/io/FileTestStorage; 浓咖啡测试android中的多个匹配项 - multi matchs in espresso test android Android设备物理旋转读数 - Android Device Physical Rotation readings Android Espresso:java.lang.NoClassDefFoundError:解析失败:Landroidx/test/platform/io/FileTestStorage; - Android Espresso: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/platform/io/FileTestStorage; AWS Device Farm + Espresso:在AWS Device Farm中运行涉及本机JNI方法调用的Espresso Instrumentation测试 - AWS Device Farm + Espresso: Running Espresso Instrumentation Test involving Native JNI method call in AWS Device Farm 使用@Parameters的Android Espresso测试需要上下文 - Android Espresso test with @Parameters needs context Android Studio 看不到我的物理设备 - Android Studio does not see my physical device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM