pedrovgs / Shot

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

Failing to record screenshots #334

Open tripolkaandrey opened 1 year ago

tripolkaandrey commented 1 year ago

Preface

I am integrating screenshot testing in my Jetpack Compose application. Despite trying different library versions(5.+) and API levels(26-33), I always have some issues. I decided to pick one "combination" and, therefore, issue in the hope of getting some help—and hopefully, insight into issues with other configurations.

Dependencies

Shot => 5.14.1 Jetpack Compose => 1.3.1 Android Gradle Plugin => 7.3.1

Configuration

// `shot-configuration.gradle.kts`

plugins {
    id("com.android.application")
    id("shot")
}

shot {
    tolerance = 1.0 // 1%
}

dependencies {
    androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.3.1")
    debugImplementation("androidx.compose.ui:ui-test-manifest:1.3.1")
}

android {
    defaultConfig {
        testInstrumentationRunner = "com.karumi.shot.ShotTestRunner"
    }
}

Sample

class SampleTest : ScreenshotTest {

    @get:Rule
    val composeRule = createComposeRule()

    @Test
    fun test() {
        composeRule.setContent {
            Card {
                Text("I am a sample test.")
            }
        }
        compareScreenshot(composeRule)
    }
}

Device

I am launching an emulator with Pixel 6 API 30 via Android Studio.

Command

./gradlew executeScreenshotTests -Precord

Output

> Task :app:debugDownloadScreenshots
⬇️  Pulling screenshots from your connected devices!
Shot ADB warning: We could not pull screenshots from folder: /storage/emulated/0/Download/screenshots/app.test/screenshots-default/
Shot ADB warning: We could not pull screenshots from folder: /storage/emulated/0/Download/screenshots/app.test/screenshots-compose-default/
Shot ADB warning: rm: /storage/emulated/0/Download/screenshots/app.test/screenshots-default/: No such file or directory

> Task :app:debugExecuteScreenshotTests
💾  Saving screenshots.
🤔 We couldn't find any screenshot. Did you configure Shot properly and added your tests to your project? https://github.com/pedrovgs/Shot/#getting-started

Behaviour

The emulator seems to be doing the work while running the command. However, afterwards, there are no screenshots on the device and in the local screenshots directory.

sergio-sastre commented 1 year ago

@tripolkaandrey For API 28-33 you need to enable non-SDK interfaces on your emulator via adb: https://github.com/pedrovgs/Shot#using-shot-on-api-28

are you doing that?

tripolkaandrey commented 1 year ago

@sergio-sastre Thank you for your suggestion. Yes, I did enable it.

sergio-sastre commented 1 year ago

@tripolkaandrey Do you have a windows machine? Someone reportes similar error to me in this repo: https://github.com/sergio-sastre/Android-screenshot-testing-playground/issues/20

However, I do run it without any issues. Could you check out if you also get the same error?

tripolkaandrey commented 1 year ago

@sergio-sastre

Do you have a windows machine?

No, I am using macOS.

lucas-livefront commented 1 year ago

I am experiencing the same issue.

Venkat-juju commented 1 year ago

Same issue... but in my another project it is working fine... Actually for the first time it worked when recording... Then it is not working.. I'm not sure why

HardSea commented 1 year ago

After few hours of debugging, I found the problem...

The reason is that there are spaces in the project folder name or in the project path. Removing the spaces moved the screenshots to the project folder and fixed the error: 🤔 We couldn't find any screenshot. Did you configure Shot properly and added your tests to your project? https://github.com/pedrovgs/Shot/#getting-started

@pedrovgs Please, fix the problem or describe it in the documentation

Venkat-juju commented 5 months ago

My build was having minify enabled in the debug build and when i run screenshot tests for the debug build.. the screenshots were not pulled... after disabling minify, it is working find