Errors thrown when attempting to generate diff image files for Compose views
Describe the bug
Attempting to record a diff image on a failed Compose screenshot test leads to a java.lang.RuntimeException: Buffer not large enough for pixels error
This issue relates to:
- [x] The Kotlin library
- [ ] The Gradle plugin
- [ ] The IntelliJ Platform plugin
- [ ] The sample code
- [ ] The documentation
To Reproduce
Steps to reproduce the behavior:
Create a screenshot test using the ComposableScreenshotRule and enable the TestifyFeatures.GenerateDiffs option. Create a screenshot reference and then update the UI such that it is different. Then run the test (expected to fail). An updated screenshot is written out (as expected) but the diff image is not created. In the logs it appears there is an error that is thrown when creating the diff image (java.lang.RuntimeException: Buffer not large enough for pixels)
Here is the call stack I'm seeing in the logs:
java.lang.RuntimeException: Buffer not large enough for pixels
at android.graphics.Bitmap.copyPixelsToBuffer(Bitmap.java:636)
at dev.testify.internal.processor.ParallelPixelProcessor.prepareBuffers(ParallelPixelProcessor.kt:39)
at dev.testify.internal.processor.ParallelPixelProcessor.transform(ParallelPixelProcessor.kt:97)
at dev.testify.internal.processor.diff.HighContrastDiff.generate(HighContrastDiff.kt:24)
at dev.testify.ScreenshotRule.generateHighContrastDiff(ScreenshotRule.kt:423)
at dev.testify.ScreenshotRule.assertSame(ScreenshotRule.kt:534)
at com.xxxx.android.example.ExampleComposeSnapshotTests$test_instrumentation_snapshot_tests_integration_for_compose$3.invoke(ExampleComposeSnapshotTests.kt:20)
at com.xxxx.android.example.ExampleComposeSnapshotTests$test_instrumentation_snapshot_tests_integration_for_compose$3.invoke(ExampleComposeSnapshotTests.kt:15)
at com.kaspersky.kaspresso.testcases.core.TestRunner.runMainTestSection(TestRunner.kt:146)
at com.kaspersky.kaspresso.testcases.core.TestRunner.run(TestRunner.kt:59)
at com.kaspersky.kaspresso.testcases.core.sections.MainTestSection.run(MainTestSection.kt:29)
at com.xxxx.android.example.ExampleComposeSnapshotTests.test_instrumentation_snapshot_tests_integration_for_compose(ExampleComposeSnapshotTests.kt:15)
Here is our setup for the rule:
@get:Rule
val composeScreenshotRule = ComposableScreenshotRule()
.configure {
exactness = 0.95f
}
.withExperimentalFeatureEnabled(TestifyFeatures.GenerateDiffs)
as ComposableScreenshotRule
Is there any insight you can provide here about what might be causing this issue or how we might fix this? / Does our setup look correct for this approach?
Thanks for any help you can provide!
Expected behavior
I would expect the diff image file is created and written to disk. Note: The ScreenshotRule with similar setup works fine and outputs a diff image.
Screenshots If applicable, add screenshots to help explain your problem.
Target Android Device (please complete the following information):
- Device: Android Emulator and actual device on AWS DeviceFarm (Samsung Galaxy S21)