pedrovgs / Shot

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

Failed to grant permissions #325

Closed DerekBeam closed 1 year ago

DerekBeam commented 1 year ago

Expected behaviour

I expect to not have to include undesired permissions in order for Shot to record screenshots.

Actual behaviour

I'm using Showkase to automatically create my snapshot tests with Shot on Windows. This is working as intended. A sample setup is located here: https://github.com/davidvavra/showkase-screenshot-tests/tree/shot

@ShowkaseScreenshot(rootShowkaseClass = ShowkaseModule::class)
abstract class ComposeTests : ShowkaseScreenshotTest, ScreenshotTest {

    override fun onScreenshot(
        id: String,
        name: String,
        group: String,
        styleName: String?,
        screenshotType: ShowkaseScreenshotType,
        screenshotBitmap: Bitmap
    ) {
        compareScreenshot(bitmap = screenshotBitmap, name = "$group - $name")
    }
}
@ShowkaseRoot
class ShowkaseModule : ShowkaseRootModule

When I attempt to record my snapshots, I get the following error message:

com.beamimpact.beam.ComposeTests_ShowkaseCodegen > color_screenshot_test_14[Pixel_6_Pro_API_32(AVD) - 12] FAILED 
        junit.framework.AssertionFailedError: Failed to grant permissions, see logcat for details
        at junit.framework.Assert.fail(Assert.java:50)

I'm able to fix this by adding the following permissions to my app/src/main/AndroidManifest.xml file:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

However, I don't want these permissions in my actual app. I want them to only be active for the instrumented test.

I tried adding those permissions to an app/src/androidTest/AndroidManifest.xml but it did not fix the problems. It only seems fixed when I include it in the app's AndroidManifest.xml.

Steps to reproduce

  1. Include and configure showkase
  2. Include and configure shot
  3. Add ComposeTests class to androidTest
  4. Run .\gradlew.bat debugExecuteScreenshotTests -Precord

Version of the library

DerekBeam commented 1 year ago

I also tried adding in the sharedUserId to the manifest per the README instructions, but then I get the error below. I'm not sure if that is related or not.

> Task :app:connectedDebugAndroidTest FAILED
Exception thrown during onBeforeAll invocation of plugin com.google.testing.platform.plugin.android.AndroidDevicePlugin.
Failed to install APK(s): app\build\outputs\apk\androidTest\debug\app-debug-androidTest.apk
INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: Package <my-package> tried to change user null
com.android.ddmlib.InstallException: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: Package <my-package> tried to change user null
        at com.android.ddmlib.internal.DeviceImpl.installRemotePackage(DeviceImpl.java:1315)
        at com.android.ddmlib.internal.DeviceImpl.installPackage(DeviceImpl.java:1141)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDevice.installPackage(DdmlibAndroidDevice.kt)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDeviceController$executeAsync$deferred$1.invokeSuspend(DdmlibAndroidDeviceController.kt:173)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
DerekBeam commented 1 year ago

I was able to fix this by adding the AndroidManfiest to the debug folder instead