pedrovgs / Shot

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

Issue on first test run because of UiAutomation #166

Closed stephen1706 closed 3 years ago

stephen1706 commented 4 years ago

Expected behaviour

Running test will run smoothly

Actual behaviour

The first test case will always fail because of Error while connecting UiAutomation. Other test will run fine, but since the first test will always error, no report will be generated. Error log:

...
03:09:40.353 [INFO] [com.android.build.gradle.internal.LibraryTaskManager] [RemoteAndroidTest]: Running am instrument -w -r --no_window_animation  testPackage/com.karumi.shot.ShotTestRunner on emulator(AVD) - 8.1.0
03:09:43.991 [LIFECYCLE] [org.gradle.api.Task] Starting 8 tests on emulator(AVD) - 8.1.0
03:09:44.117 [LIFECYCLE] [org.gradle.process.internal.health.memory.MemoryManager] 
03:09:44.117 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting OS memory status event {Total: 15770062848, Free: 9547132928}
03:09:44.117 [DEBUG] [org.gradle.launcher.daemon.server.health.LowMemoryDaemonExpirationStrategy] Received memory status update: {Total: 15770062848, Free: 9547132928}
03:09:44.117 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting JVM memory status event {Maximum: 1431830528, Committed: 1146617856}
03:09:49.117 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting OS memory status event {Total: 15770062848, Free: 9546784768}
03:09:49.117 [DEBUG] [org.gradle.launcher.daemon.server.health.LowMemoryDaemonExpirationStrategy] Received memory status update: {Total: 15770062848, Free: 9546784768}
03:09:49.117 [DEBUG] [org.gradle.process.internal.health.memory.MemoryManager] Emitting JVM memory status event {Maximum: 1431830528, Committed: 1146617856}
0
02:43:52.580 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] 
02:43:52.580 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :module:connectedDebugAndroidTest
02:43:57.933 [WARN] [org.gradle.api.Task] 
testClass > test1[emulator(AVD) - 8.1.0] FAILED 
02:43:57.933 [WARN] [org.gradle.api.Task]   java.lang.RuntimeException: Error while connecting UiAutomation
    at android.app.UiAutomation.connect(UiAutomation.java:239)
02:43:59.566 [INFO] [org.gradle.api.Task] 
testClass > test2[emulator(AVD) - 8.1.0] SUCCESS 
...

Steps to reproduce

Run ./gradlew executeScreenshotTests -d at emulator API 27 at bitrise. The issue is not reproducible at my local mac machine. The stack of my bitrise machine is using linux.

Version of the library

4.4.0

pedrovgs commented 3 years ago

Hi @stephen1706 I'm afraid this issue seems not to be related to Shot at all. We are not using UI automation API so there is nothing we can do to fix it. I'm afraid I'm closing this issue.

amatsegor commented 10 months ago

Looks like, unfortunately, indirectly (through Facebook testing library) we do. Here's a full stacktrace for this issue. SDK version on emulator: 26, emulator version: 34.1.1

20:57:42.913  E  Exception captured while taking screenshot for snapshot with name

                 java.lang.RuntimeException: Error while connecting UiAutomation
                    at android.app.UiAutomation.connect(UiAutomation.java:239)
                    at android.app.Instrumentation.getUiAutomation(Instrumentation.java:2045)
                    at android.app.Instrumentation.getUiAutomation(Instrumentation.java:2002)
                    at com.facebook.testing.screenshot.internal.ScreenshotDirectories.grantPermission(ScreenshotDirectories.java:77)
                    at com.facebook.testing.screenshot.internal.ScreenshotDirectories.checkPermissions(ScreenshotDirectories.java:68)
                    at com.facebook.testing.screenshot.internal.ScreenshotDirectories.get(ScreenshotDirectories.java:53)
                    at com.facebook.testing.screenshot.internal.AlbumImpl.<init>(AlbumImpl.java:52)
                    at com.facebook.testing.screenshot.internal.AlbumImpl.create(AlbumImpl.java:61)
                    at com.facebook.testing.screenshot.internal.ScreenshotImpl.create(ScreenshotImpl.java:76)
                    at com.facebook.testing.screenshot.internal.ScreenshotImpl.getInstance(ScreenshotImpl.java:94)
                    at com.facebook.testing.screenshot.Screenshot.snap(Screenshot.java:39)
                    at com.karumi.shot.ScreenshotTest$DefaultImpls.takeViewSnapshot(ScreenshotTest.kt:187)
                    at com.karumi.shot.ScreenshotTest$DefaultImpls.compareScreenshot(ScreenshotTest.kt:110)
                    at my.project.BaseViewTest.compareScreenshot(BaseViewTest.kt:27)