pedrovgs / Shot

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

-Precord param not working on api 28+ #246

Open Stronger197 opened 3 years ago

Stronger197 commented 3 years ago

Expected behaviour

Screenshots are successfully generated for cases declared in the sample app

@Test
fun showsAnySuperHero() {
    val superHero = givenASuperHero()
    val holder = givenASuperHeroViewHolder()
    holder.render(superHero)
    compareScreenshot(holder)
}

Actual behaviour

Test completes successfully, but screenshots folder is empty and no errors are generated

Steps to reproduce

Open shot-consumer-flavors Create new avd 28+ Run executeScreenshotTests with following params -Pandroid.testInstrumentationRunnerArguments.class=com.karumi.ui.view.SuperHeroViewHolderTest -Precord

Check the "screenshots" folder when execution is finished

Version of the library

5.11.0 but it also doesn't work in lower versions Tested on api 28+

Possible solution

I think this is happens because of restrictions on non-SDK interfaces (API 28+) So, when I executed the following command, everything works fine

Android 9 (API level 28)
adb shell settings put global hidden_api_policy_pre_p_apps 1
adb shell settings put global hidden_api_policy_p_apps 1
Android 10 (API level 29) or higher
adb shell settings put global hidden_api_policy 1

@pedrovgs How about adding this info to the docs, because I spent a lot of time to launch this type of tests?

pedrovgs commented 3 years ago

oO first time I see this. Thanks for reporting @Stronger197. Could you please send a PR with a README.md update explaining this scenario?

Stronger197 commented 3 years ago

Yep, sure!

Stronger197 commented 3 years ago

I have more info. If you run compareScreenshot(view : View) without -Precord param, it also not working as expected, because /build/reports/shot/verification/images is empty

pedrovgs commented 3 years ago

Are you sure this is a library issue and not something related to your project or your config? Could you try running shot-consumer or any other consumer example app inside this repository in your testing device to ensure we have a real bug?

Stronger197 commented 3 years ago

Pls read "Steps to reproduce". I tested this case using shot-consumer-flavors. compareScreenshot(view : View) - not working compareScreenshot(activity : Activity) - ok

kdk96 commented 3 years ago

Hi. I reproduced this problem too on shot-consumer.

pedrovgs commented 3 years ago

Hi all! I'm going to be out for holiday so if anybody knows how to fix this issue without dealing with the emulators, please let me know and contribute if possible. It could be great if we can find another alternative to -P param to be able to record our screenshots. This feature should work out of the box without any further configuration

sergio-sastre commented 3 years ago

Not sure whether this is related to this issue, but worth mentioning. I have seen similar issues happening on the KataScreenshotKotlin

It seems the problems start with Shot 5.8.0

I cloned the project locally. It has shot version 5.5.0 configured and that one works fine (Gradle 6.7.1, emulator: Marshmallow API 23, targetSdk 28)

But if we just change the shot version, we experience the following problems: Shot 5.7.0 (still fine)

shot 5 7 0

Shot 5.8.0

shot 5 8 0

Shot 5.11.2

shot 5 11 2

Moreover, I tried with the aforementioned "workaround" on a device with API 30 and Shot 5.11.2 and it fails

I've checked the Readme and saw that the following was added in Shot 5.8.0: "Since Shot 5.8.0 we provide support for devices running API >= 29. There is no need to configure android:requestLegacyExternalStorage="true" or provide any special storage permission in your test `AndroidManifest."

That's my investigation so far

sergio-sastre commented 3 years ago

Not sure whether this is related to this issue, but worth mentioning. I have seen similar issues happening on the KataScreenshotKotlin

It seems the problems start with Shot 5.8.0

I cloned the project locally. It has shot version 5.5.0 configured and that one works fine (Gradle 6.7.1, emulator: Marshmallow API 23, targetSdk 28)

But if we just change the shot version, we experience the following problems: Shot 5.7.0 (still fine)

shot 5 7 0

Shot 5.8.0

shot 5 8 0

Shot 5.11.2

shot 5 11 2

Moreover, I tried with the aforementioned "workaround" on a device with API 30 and Shot 5.11.2 and it fails

I've checked the Readme and saw that the following was added in Shot 5.8.0: "Since Shot 5.8.0 we provide support for devices running API >= 29. There is no need to configure android:requestLegacyExternalStorage="true" or provide any special storage permission in your test `AndroidManifest."

That's my investigation so far

I found out that it was not working because that kata is using its own testRunner instead of com.karumi.shot.ShotTestRunner, so it is not relevant to this bug. I think it would be great to update the Kata to the latest shot version. It can serve as example to other people having issues to configure Shot. Sorry for misleading :(

raafaelima commented 3 years ago

Hey Folks,

Since I update my project to use the API 31 (Android R), I'm having kinda the same issues. The test runs Ok, however, the snapshot folder can be found or created. I can't figure out what is wrong, to be honest. Could you guys help me to understand?

I'm using an AndroidAuto emulator to develop, however, the behavior is reproducible on my Pixel Emulator too.

I created a sample app with the same configuration that I have on my real project, you can find it here: https://github.com/raafaelima/ShotSnapshotSample

Screenshot 2021-10-22 at 12 58 26

BenedictP commented 2 years ago

@raafaelima I'm having the same issue and it's blocking us to introduce Shot in our codebase. Have you found any solution so far?