mobile-dev-inc / maestro

Painless Mobile UI Automation
https://maestro.mobile.dev/
Apache License 2.0
5.73k stars 264 forks source link

Fail to run on AWS Device Farm for Android >= 10 #425

Closed Almouro closed 1 month ago

Almouro commented 1 year ago

Hi! Thanks for providing Maestro to the community! ❤️

Trying to run Maestro in AWS Device Farm, I've noticed Android devices with version 10 and above will fail to run Maestro (basically devices supporting abb_exe)

It fails here: https://github.com/mobile-dev-inc/dadb/blob/master/dadb/src/main/kotlin/dadb/Dadb.kt#L85 seemingly printing out the output of running adb shell cmd package as if everything after package was ignored:

java.io.IOException: Failed to install apk /tmp/maestro-app8381517088354451654.apk: Install failed: Package manager (package) commands:
  help
    Print this help text.

  path [--user USER_ID] PACKAGE

...

    at dadb.Dadb$DefaultImpls.install(Dadb.kt:85)
    at dadb.adbserver.AdbServerDadb.install(AdbServer.kt:118)
    at maestro.drivers.AndroidDriver.install(AndroidDriver.kt:424)
    ... 15 more

If I run Dadb from source on AWS, I'm running into the same issue. I can log the commands sent via abb:

For instance, with:

val dadb = Dadb.discover()
val workingDir = System.getProperty("user.dir")
dadb?.install(File(workingDir + File.separator + "blank.apk"))

I see:

host:devices
host:transport:R9AR207LM2J
host:features
host:transport:R9AR207LM2J
abb_exec:packageinstall-S1656660

If I force dadb to use the second version to install an APK (without abb), it works succesfully.

Kinda wondering if there is an issue with the null symbol \u0000 not being recognized somehow on AWS machines. AWS Device Farm runs with Ubuntu 14 LTS / Java 8 / adb 1.0.39. I've upgraded both java and adb and I'm still running in the same issue though

Any ideas what could be going on, what to try out next?

vibin commented 1 year ago

Hi @Almouro - are you using Custom test environments in AWS device farm? If yes, can you share the install and pre_test phases of your AWS device farm script?

Almouro commented 1 year ago

Hi @vibin, sure here's a simple example to reproduce:

version: 0.1

phases:
  install:
    commands:
      - curl -Ls "https://get.maestro.mobile.dev" | bash
      - export PATH="$PATH":"$HOME/.maestro/bin"
      - echo YXBwSWQ6IGNvbS5leGFtcGxlCi0tLQotIGxhdW5jaEFwcAotIGFzc2VydFZpc2libGU6IC4qLioK | base64 -d > test.yaml
  test:
    commands:
      - maestro test test.yaml
vibin commented 1 year ago

Hi @vibin, sure here's a simple example to reproduce:

version: 0.1

phases:
  install:
    commands:
      - curl -Ls "https://get.maestro.mobile.dev" | bash
      - export PATH="$PATH":"$HOME/.maestro/bin"
      - echo YXBwSWQ6IGNvbS5leGFtcGxlCi0tLQotIGxhdW5jaEFwcAotIGFzc2VydFZpc2libGU6IC4qLioK | base64 -d > test.yaml
  test:
    commands:
      - maestro test test.yaml

Hi @Almouro, you mentioned you tried upgrading ADB. Is that done as part of the install phase? Can you share the snippet for that?

Almouro commented 1 year ago

Indeed, here goes:

version: 0.1

phases:
  install:
    commands:
      # Upgrade java
      - java -version
      - curl -s "https://get.sdkman.io" | bash
      - source "$HOME/.sdkman/bin/sdkman-init.sh"
      - sdk install java
      - echo "Java upgraded"
      - java -version
      # Upgrade adb
      - adb version
      - wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
      - unzip platform-tools-latest-linux.zip
      - export PATH=$(pwd)/platform-tools:$PATH
      - echo "ADB upgraded"
      - adb version
      # Install Maestro
      - curl -Ls "https://get.maestro.mobile.dev" | bash
      - export PATH="$PATH":"$HOME/.maestro/bin"
      - echo YXBwSWQ6IGNvbS5leGFtcGxlCi0tLQotIGxhdW5jaEFwcAotIGFzc2VydFZpc2libGU6IC4qLioK | base64 -d > test.yaml
  test:
    commands:
      - maestro test test.yaml
tomoakley commented 1 year ago

I'm also experiencing the same issue.

If I force dadb to use the second version to install an APK (without abb), it works succesfully.

@Almouro can you share some more details on what this means? How is that achieved?

Were you able to find a workaround to get Maestro + AWS DF to work together?

vibin commented 1 year ago

Hi @tomoakley, I think @Almouro is referring to the if-else conditional in the Dadb.install function.

    fun install(file: File, vararg options: String) {
        if (supportsFeature("abb_exec")) {
            abbExec("package", "install", "-S", file.length().toString(), *options).use { stream ->
                stream.sink.writeAll(file.source())
                stream.sink.flush()
                val response = stream.source.readString(Charsets.UTF_8)
                if (!response.startsWith("Success")) {
                    throw IOException("Install failed: $response")
                }
            }
        } else {
            val fileName = file.name
            val remotePath = "/data/local/tmp/$fileName"
            push(file, remotePath)
            shell("pm install ${options.joinToString(" ")} \"$remotePath\"")
        }
    }

More on abb_exec here: https://malinskiy.github.io/adam/docs/abb

Though, how to execute the else branch on Android 10+ remains unknown...

Almouro commented 1 year ago

Indeed, we just forked it replacing the condition with if (false) 🙈

Since we have node installed on the aws machine, we run it with npx @perf-profiler/maestro@rc test instead of just maestro test

tomoakley commented 1 year ago

thanks @vibin @Almouro, very helpful. Will try using that package and see if it works for me!

edit: it works! thanks so much @Almouro 🎉

khoafonos commented 1 year ago

@Almouro : can you update @perf-profiler/maestro since its missing --debug-output command

vibin commented 1 year ago

Dadb v1.2.7 replaces abb_exec with exec:cmd: https://github.com/mobile-dev-inc/dadb/pull/63

Waiting for Maestro to upgrade Dadb to new version... https://github.com/mobile-dev-inc/maestro/blob/ce0e2f74feecafded81baa727240488436056509/gradle/libs.versions.toml#L19-L21

vibin commented 1 year ago

@axelniklasson @Leland-Takamine Could you please take up the Dadb upgrade in the next Maestro release?

Almouro commented 1 month ago

Retested with latest Maestro version and it works for me now 👌🥳

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar problem, please file a new issue. Make sure to follow the template and provide all the information necessary to reproduce the issue. Thank you for helping keep us our issue tracker clean!