Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not pull record screenshots from the phone to the project on Windows 10 #140

Closed
vnhanh opened this issue Sep 22, 2020 · 18 comments · Fixed by #266
Closed

Can not pull record screenshots from the phone to the project on Windows 10 #140

vnhanh opened this issue Sep 22, 2020 · 18 comments · Fixed by #266

Comments

@vnhanh
Copy link

vnhanh commented Sep 22, 2020

Expected behaviour

Run command to record screenshots and get recorded screenshots in images/recorded folder and screenshots folder in the project on Windows 10

Actual behaviour

I didn't see recorded screenshots in my project although terminal of Android Studio notify pulling screenshots successfully

Steps to reproduce

  1. Run the command on Windows 10: gradlew mockWebServerMobileNativeDebugExecuteScreenshotTests -Precord -Pandroid.testInstrumentationRunnerArguments.class=my_testcase.
  2. Terminal of Android Studio notice that task done successfully.
    image
  3. The images/record folder doesn't contain record screenshots as my expectation.
    image
    The screenshots folder also doesn't contains the record screenshots.

Version of the library

4.3.0, 4.4.0

  • I used Gradle 5.4.1.
  • On MacOS 10.15.6, I can run record screenshots command and get the record screenshots.
@pedrovgs
Copy link
Owner

pedrovgs commented Oct 1, 2020

It has to be something with the paths in windows. We had no time to provide full support for Shot in windows because nobody in our team uses this OS and it was not a priority for us. If any contributor in Shot using windows could review this one ,that'd be really helpful.

@anavasHiberus
Copy link

@vnhanh Did you get to solve this Karumi path bug? My team has stucked finding a solution by 3 days and not a clue about how to solve it. We have exactly the same problem than you.

Thanks in advance. If you, @pedrovgs , have already developed a solution we would be pleased to know it as we would like tou use this test tool.

Regards!

@vnhanh
Copy link
Author

vnhanh commented Mar 30, 2021

Sorry, I havn't found any solution and my company ignored recording screenshots on Windows machine.

@pedrovgs
Copy link
Owner

FYI we keep looking for a contributor who could help us with the windows support.

@anavasHiberus
Copy link

anavasHiberus commented May 20, 2021 via email

@souissihaythem
Copy link

Thank you , I wasted one day checking my Karumi implementation because of this.
Can please add this detail in your documentation: Karumi can't be used on WinDows10 computer.

And in this class https://github.com/Karumi/Shot/blob/master/core/src/main/scala/com/karumi/shot/android/Adb.scala
can you change the log line to this:
Console.YELLOW + s"Shot ADB warning: We could not pull screenshots from folder: ${folderToPull}" + " error = " + e.getMessage()

So we can get more details about the occured problem

@DSteve595
Copy link

I'd be happy to try and fix the Windows version, but in my own project on Windows 10, Shot is able to pull screenshots just fine. Can you provide a sample project?

@pedrovgs
Copy link
Owner

pedrovgs commented Jul 1, 2021

Thanks @DSteve595 😃

@mariuszmarzec
Copy link
Contributor

@DSteve595 @pedrovgs I checked one of sample project (https://github.com/pedrovgs/Shot/tree/master/shot-consumer/samplelibrary) on my windows 10 and it doesn't work. It is interesting because screenshot-bundle.zip and other dumped images under build/report/shot dir are fetched
obraz

@mariuszmarzec
Copy link
Contributor

mariuszmarzec commented Nov 26, 2021

@pedrovgs I made some investigations and it is caused by used file path separator in the code. Now / is used. For windows should be \. I fixed it locally by adding dynamic (depending on system) separator in Config object in model.scala file.

@mariuszmarzec
Copy link
Contributor

@pedrovgs
I made some additional investigations and i realized that verifiy task is broken too. Minimal fix for windows for record and verifiy is making temporary dir path depending on OS:

  private val isWindows: Boolean = System.getProperty("os.name").startsWith("Windows")
  val screenshotsTemporalRootPath: FilePath = if (isWindows) {
    System.getenv("localappdata") + "\\Temp\\screenshots\\"
  } else {
    "/tmp/shot/screenshot/"
  }

Second things needs to be done is fixing getting metadataFiles in readScreenshotsMetadata in Shot.scala file.
Current implementation is basing on comparing potential metadata file absulute path with result of metadataFileName from Config class. But Config.metadataFileName returns path not name and for windows absolute path contains \ char as separator,
Config.metadataFileName returns path build upon unix separator /. Easiest way to fix:
In 284 line of Shot.scala changing comparision to smth like below:

    if (folder.exists()) {
      val filesInScreenshotFolder = folder.listFiles
      val metadataFiles = filesInScreenshotFolder.filter(file =>
        file.getAbsolutePath.contains("metadata.xml")
      )

@pedrovgs
Copy link
Owner

pedrovgs commented Dec 7, 2021

Could somebody please check if the PR @mariuszmarzec sent works on Windows? The code looks great but I'd like to confirm. @voghDev @sergio-sastre or any other contributor? I'd really appreciate if you can find some time to run the tests the repository contains. You just need to execute these commands:

./gradlew publishToMavenLocal
cd shot-consumer
./gradlew executeScreenshotTests

I'm asking for a CI configuration on windows, but this is not straight forward and I'd like to publish the fix soon if we can guarantee this is working fine on Windows 😃

@rock3r
Copy link

rock3r commented Dec 12, 2021

We're still having there issues on github.com/code-with-the-italians/bundel on 5.12.1 unfortunately. Same error as the original report. I'll put a link to the recording of our efforts once the recording is out!

EDIT: wrong issue!

@pedrovgs
Copy link
Owner

@rock3r could you please clone this repository and try with shot-consumer-flavors example project? You can run ./gradlew executeScreenshotTests -P record to save the golden images and then verify your screenshots again with ./gradlew executeScreenshotTests. I tried with API 28 and created an emulator with an SDCard for my local tests.

@rock3r
Copy link

rock3r commented Dec 12, 2021

Sure thing, will do tomorrow

@rock3r
Copy link

rock3r commented Dec 13, 2021

I just realised I put the comment on the wrong issue. It was meant for #244, sorry!

@josehector
Copy link

@pedrovgs I tried shot-consumer-flavor example project on windows 10 and it was right. Even I changed a layout in order to verify a fail.
I tried it with API 29.

@voghDev
Copy link
Contributor

voghDev commented Dec 16, 2021

Hi!
I tried to execute shot-consumer tests on Windows 10 and this was the result 👇

C:\Users\User\projects\android\Shot\shot-consumer>gradlew executeScreenshotTests
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :app
Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01

> Configure project :app2
Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.

> Task :app:processDebugMainManifest
[androidx.vectordrawable:vectordrawable-animated:1.0.0] C:\Users\User\.gradle\caches\transforms-3\d3621845842eee9887e1fd01fa54c9e5\transformed\vectordrawable-animated-1.0.0\AndroidManifest.xml Warning:
        Package name 'androidx.vectordrawable' used in: androidx.vectordrawable:vectordrawable-animated:1.0.0, androidx.vectordrawable:vectordrawable:1.0.0.

> Task :app:compileDebugJavaWithJavac
The following annotation processors are not incremental: lifecycle-compiler-2.0.0.jar (androidx.lifecycle:lifecycle-compiler:2.0.0).
Make sure all annotation processors are incremental to improve your build speed.
Shot ADB warning: rm: /storage/emulated/0/Download/screenshots/com.karumi.test/screenshots-default/: No such file or directory
Shot ADB warning: rm: /storage/emulated/0/Download/screenshots/com.karumi.test/screenshots-compose-default/: No such file or directory
Shot ADB warning: rm: /storage/emulated/0/Download/screenshots/com.karumi.test/screenshots-default/: No such file or directory
Shot ADB warning: rm: /storage/emulated/0/Download/screenshots/com.karumi.test/screenshots-compose-default/: No such file or directory

> Task :app2:processDebugMainManifest
[androidx.vectordrawable:vectordrawable-animated:1.0.0] C:\Users\User\.gradle\caches\transforms-3\d3621845842eee9887e1fd01fa54c9e5\transformed\vectordrawable-animated-1.0.0\AndroidManifest.xml Warning:
        Package name 'androidx.vectordrawable' used in: androidx.vectordrawable:vectordrawable-animated:1.0.0, androidx.vectordrawable:vectordrawable:1.0.0.

> Task :app2:compileDebugJavaWithJavac
The following annotation processors are not incremental: lifecycle-compiler-2.0.0.jar (androidx.lifecycle:lifecycle-compiler:2.0.0).
Make sure all annotation processors are incremental to improve your build speed.

> Task :app:testDebugComposer
[Wed Dec 15 19:59:56 CET 2021]: 1 connected adb device(s): [AdbDevice(id=emulator-5554, model=Android SDK built for x86, online=true)]
[Wed Dec 15 19:59:56 CET 2021]: [emulator-5554] 2 APKs to install
[Wed Dec 15 19:59:56 CET 2021]: [emulator-5554] 1: C:\Users\User\projects\android\Shot\shot-consumer\app\build\outputs\apk\debug\app-debug.apk
[Wed Dec 15 19:59:56 CET 2021]: [emulator-5554] 2: C:\Users\User\projects\android\Shot\shot-consumer\app\build\outputs\apk\androidTest\debug\app-debug-androidTest.apk
[Wed Dec 15 19:59:56 CET 2021]: [emulator-5554] Acquiring lock
[Wed Dec 15 19:59:56 CET 2021]: [emulator-5554] Lock acquired
[Wed Dec 15 19:59:56 CET 2021]: [emulator-5554] Installing apk... pathToApk = C:\Users\User\projects\android\Shot\shot-consumer\app\build\outputs\apk\debug\app-debug.apk
[Wed Dec 15 19:59:57 CET 2021]: [emulator-5554] Successfully installed apk in 1 second, pathToApk = C:\Users\User\projects\android\Shot\shot-consumer\app\build\outputs\apk\debug\app-debug.apk
[Wed Dec 15 19:59:57 CET 2021]: [emulator-5554] Installing apk... pathToApk = C:\Users\User\projects\android\Shot\shot-consumer\app\build\outputs\apk\androidTest\debug\app-debug-androidTest.apk
[Wed Dec 15 19:59:59 CET 2021]: [emulator-5554] Successfully installed apk in 1 second, pathToApk = C:\Users\User\projects\android\Shot\shot-consumer\app\build\outputs\apk\androidTest\debug\app-debug-androidTest.apk
[Wed Dec 15 19:59:59 CET 2021]: [emulator-5554] Starting tests...
[Wed Dec 15 20:00:08 CET 2021]: [emulator-5554] Test 1/19 failed in 3 seconds: com.karumi.ui.view.CursorActivityTest.cursorIsNotVisibleOnScreenshot
... a lot of PASSED tests here ...
com.karumi.ui.view.SuperHeroViewHolderTest.showsAvengersBadge
[Wed Dec 15 20:00:25 CET 2021]: [emulator-5554] Test 19/19 passed in 0 seconds: com.karumi.ui.view.SuperHeroViewHolderTest.showsSuperHeroesWithLongDescriptions
[Wed Dec 15 20:00:26 CET 2021]: [emulator-5554] Test run finished, 18 passed, 1 failed, took 27 seconds.
[Wed Dec 15 20:00:27 CET 2021]: Generating HTML report...
[Wed Dec 15 20:00:27 CET 2021]: HTML report generated, took 0 seconds.
[Wed Dec 15 20:00:27 CET 2021]: Test run finished, total passed = 18, total failed = 1, total ignored = 0, took 31 seconds.
[Wed Dec 15 20:00:27 CET 2021]: [emulator-5554] Lock released
[Wed Dec 15 20:00:27 CET 2021]: Error: There were failed tests.

Composer Html Report: file://C:\Users\User\projects\android\Shot\shot-consumer\app\build\reports\composer\debug\html-report\index.html


> Task :app:testDebugComposer FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:testDebugComposer'.
> Process 'command 'C:\Users\User\jdk-11.0.13\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1m 45s
77 actionable tasks: 77 executed

I think it is right. Some tests probably failed because of my emulator settings, but Shot seemed to work as expected.
These are the steps I followed:

Open Windows terminal
git clone [email protected]:pedrovgs/Shot.git
cd Shot\shot-consumer
gradlew.bat executeScreenshotTests

As a curious issue, my machine created a lockfile for the emulator, placed in an app/null/.android/commander folder:

C:\Users\User\projects\android\Shot\shot-consumer\app\null\.android\commander>dir
 Directorio de C:\Users\User\projects\android\Shot\shot-consumer\app\null\.android\commander

15/12/2021  19:59    <DIR>          .
15/12/2021  19:59    <DIR>          ..
15/12/2021  19:59                 0 emulator-5554.lock
               1 archivos              0 bytes
               2 dirs  65.398.657.024 bytes libres

I just ignored this file 😄
My emulator is a Nexus 4 (768x1232) named Nexus_5X_Api_26 with a 2GB virtual sdcard. Hope this information is helpful for you guys :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants