pedrovgs / Shot

Screenshot testing library for Android
Apache License 2.0
1.18k stars 115 forks source link

View screenshots dont work in sample app. #312

Open onreg opened 2 years ago

onreg commented 2 years ago

I am trying to check the sample app shot-consumer. But it doesn't record screenshots from SuperHeroViewHolderTest. Fragment/Activity tests work fine.

Expected behaviour

Actual behaviour

I see these errors in logcat.

2022-05-26 07:49:48.742 14084-14139/com.karumi E/Shot: Exception captured while taking screenshot for snapshot with name com.karumi.ui.view.SuperHeroViewHolderTest_showsAnySuperHero java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at com.facebook.testing.screenshot.internal.ScreenshotImpl.runCallableOnUiThread(ScreenshotImpl.java:349) at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:167) at com.facebook.testing.screenshot.internal.ScreenshotImpl.record(ScreenshotImpl.java:271) at com.facebook.testing.screenshot.internal.RecordBuilderImpl.record(RecordBuilderImpl.java:154) at com.karumi.shot.ScreenshotTest$DefaultImpls.takeViewSnapshot(ScreenshotTest.kt:177) at com.karumi.shot.ScreenshotTest$DefaultImpls.compareScreenshot(ScreenshotTest.kt:109) at com.karumi.ui.view.SuperHeroViewHolderTest.compareScreenshot(SuperHeroViewHolderTest.kt:14) at com.karumi.shot.ScreenshotTest$DefaultImpls.compareScreenshot$default(ScreenshotTest.kt:93) at com.karumi.ui.view.SuperHeroViewHolderTest.compareScreenshot(SuperHeroViewHolderTest.kt:57) at com.karumi.ui.view.SuperHeroViewHolderTest.showsAnySuperHero(SuperHeroViewHolderTest.kt:23) 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 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:2145) Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at com.facebook.testing.screenshot.WindowAttachment.generateAttachInfo(WindowAttachment.java:231) at com.facebook.testing.screenshot.WindowAttachment.dispatchAttach(WindowAttachment.java:90) at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:183) at com.facebook.testing.screenshot.internal.ScreenshotImpl.access$000(ScreenshotImpl.java:50) at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:171) at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:168) at com.facebook.testing.screenshot.internal.ScreenshotImpl$3.run(ScreenshotImpl.java:331) at android.os.Handler.handleCallback(Handler.java:873) 2022-05-26 07:49:48.743 14084-14139/com.karumi E/Shot: at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at java.lang.Class.getConstructor0(Class.java:2327) at java.lang.Class.getConstructor(Class.java:1725) at com.facebook.testing.screenshot.WindowAttachment.generateAttachInfo(WindowAttachment.java:164) ... 13 more 2022-05-26 07:49:48.748 14084-14139/com.karumi E/Shot: Exception captured while taking screenshot for snapshot with name com.karumi.ui.view.SuperHeroViewHolderTest_showsAvengersBadge java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at com.facebook.testing.screenshot.internal.ScreenshotImpl.runCallableOnUiThread(ScreenshotImpl.java:349) at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:167) at com.facebook.testing.screenshot.internal.ScreenshotImpl.record(ScreenshotImpl.java:271) at com.facebook.testing.screenshot.internal.RecordBuilderImpl.record(RecordBuilderImpl.java:154) at com.karumi.shot.ScreenshotTest$DefaultImpls.takeViewSnapshot(ScreenshotTest.kt:177) at com.karumi.shot.ScreenshotTest$DefaultImpls.compareScreenshot(ScreenshotTest.kt:109) at com.karumi.ui.view.SuperHeroViewHolderTest.compareScreenshot(SuperHeroViewHolderTest.kt:14) at com.karumi.shot.ScreenshotTest$DefaultImpls.compareScreenshot$default(ScreenshotTest.kt:93) at com.karumi.ui.view.SuperHeroViewHolderTest.compareScreenshot(SuperHeroViewHolderTest.kt:57) at com.karumi.ui.view.SuperHeroViewHolderTest.showsAvengersBadge(SuperHeroViewHolderTest.kt:53) 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 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:2145) Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at com.facebook.testing.screenshot.WindowAttachment.generateAttachInfo(WindowAttachment.java:231) at com.facebook.testing.screenshot.WindowAttachment.dispatchAttach(WindowAttachment.java:90) at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:183) at com.facebook.testing.screenshot.internal.ScreenshotImpl.access$000(ScreenshotImpl.java:50) at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:171) at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:168) at com.facebook.testing.screenshot.internal.ScreenshotImpl$3.run(ScreenshotImpl.java:331) at android.os.Handler.handleCallback(Handler.java:873) 2022-05-26 07:49:48.748 14084-14139/com.karumi E/Shot: at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at java.lang.Class.getConstructor0(Class.java:2327) at java.lang.Class.getConstructor(Class.java:1725) at com.facebook.testing.screenshot.WindowAttachment.generateAttachInfo(WindowAttachment.java:164) ... 13 more

Steps to reproduce

  1. Import the sample.
  2. Update the Gradle plugin to version 7.2.0 (without it I can't compile the project).
  3. Run Emulator API 28 (arm64-v8a).
  4. Run tests ./gradlew executeScreenshotTests -Precord

Version of the library

5.14.1

pedrovgs commented 2 years ago

Hi @onreg thanks for reporting! I've checked our CI and looks like there are no issues on this environment. Are you using somethign differnt? If the CI is able to run our tests, we should be able to reproduce it in your local environment. Maybe you are using a different java version?

onreg commented 2 years ago

Hi @pedrovgs I am using java that ships with Andoird Studio.

Screenshot 2022-05-29 at 10 58 02
amatsegor commented 8 months ago

The solution seems to be in several hidden-API-enabling flags

https://github.com/pedrovgs/Shot?tab=readme-ov-file#using-shot-on-api-28