pedrovgs / Shot

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

Wrong SDCard folder on Android 5.1 #351

Open Otacon opened 10 months ago

Otacon commented 10 months ago

Expected behaviour

When emitting ADB commands the commands should point at the same directory AndroidStorageInfo is pointing.

Actual behaviour

On the stock Google Android Emulator 5.1 (API Level 22), the saved screenshots are pointing in the right path position /storage/sdcard/, however, the rm and pull adb commands are pointing to the wrong folder /storage/emulated/0.

This causes tests to fail.

Steps to reproduce

Install android emulator default, android-22; Run the ui tests

Notice that Shot is trying to rm and pull from /storage/emulated/0. This folder doesn't exist

Version of the library

6.0.0

Suggestions

Approach 1 - Change path depending on API version

I would make the changes on my own, but I'm not that confident with Scala. So I've made some attempts and I think this might work by changing just this file core/android/ADB.scala

  1. Create a new function to dynamically gather the path

    private def baseStoragePath(device: String): String = {
    def result = executeAdbCommandWithResult(s"-s ${device} shell getprop ro.build.version.sdk")
    if(result.toInt >= 23){
      "/storage/sdcard/Downloads"
    } else {
      "/storage/emulated/0/Download"
    }
    }
  2. replace all the usages of $baseStoragePath with ${baseStoragePath(device)}

  3. remove object Adb { ... }

Approach 2 - Probably much more reliable and generic

Not sure how to implement this correctly, but probably I would:

Thank you very much for the support.