Reputation: 966
I am trying to use espresso with spoon & falcon-spoon to take automated screenshots for my app the android test app is launched successfully and took the first screenshot successfully after that and when I trying to click on button using onView(withId(buttonId)).perform(click()) it throws the below exception. I tried to downgrad the dependecies version and changing android-sdk with no result.
here the exception which is thrown.
java.lang.ClassCastException: android.os.Looper cannot be cast to org.robolectric.internal.bytecode.ShadowedObject
at org.robolectric.internal.bytecode.ShadowImpl.extract(ShadowImpl.java:14)
at org.robolectric.shadow.api.Shadow.extract(Shadow.java:25)
at org.robolectric.shadows.ShadowLooper.shadowLooper(ShadowLooper.java:39)
at org.robolectric.shadows.ShadowLooper.shadowMainLooper(ShadowLooper.java:50)
at org.robolectric.android.internal.LocalControlledLooper.drainMainThreadUntilIdle(LocalControlledLooper.java:15)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:99)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:43)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:94)
at com.dexcom.app.utils.CommonViewsHelperKt.clickNextButton(CommonViewsHelper.kt:43)
at com.dexcom.app.screen_crawler.SetupWizardScreenshots.setupWizardScreenShots(SetupWizardScreenshots.kt:49)
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 androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:130)
at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
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 androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2218)
and here is gradle dependencies I used for spoon and espresso:
dependencies {
androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
androidTestImplementation "androidx.test:rules:1.3.0"
androidTestImplementation "androidx.test:runner:1.3.0"
androidTestImplementation "com.squareup.spoon:spoon-client:2.0.0-SNAPSHOT"
androidTestImplementation "com.jraska:falcon:2.1.1"
androidTestImplementation "com.jraska:falcon-spoon-compat:2.1.1"
}
Upvotes: 2
Views: 1287
Reputation: 11
I solved this by removing the Robolectric library dependency from my main source set. I had included it to make a utility work but I remember reading that if Robolectric test runner is available it will be used as it is automatically registered if available as a dependency.
So I removed this
implementation "org.robolectric:robolectric:$ROBOLECTRIC_VERSION"
And refactored by custom utilities. The lesson here is to only have Robolectric as a dependency to your unit test source set, i.e. only using
testImplementation "org.robolectric:robolectric:$ROBOLECTRIC_VERSION"
Upvotes: 1