KasperskyLab / Kaspresso

Android UI test framework
https://kasperskylab.github.io/Kaspresso/
Apache License 2.0
1.78k stars 150 forks source link

Run `adbserver-desktop.jar` automatically during instrumentation tests #247

Open ultraon opened 3 years ago

ultraon commented 3 years ago

Hello guys, I want to thank you for this amazing Framework! And I want to suggest you providing an auto-run setup for adbserver-desktop.jar.

In the appropriate a gradle module build.gradle we need to add changes as follows:

plugins {
  // ...

    // https://github.com/hesch/gradle-execfork-plugin
    id 'com.github.hesch.execfork' version '0.1.15'
}

android {
 // ...
    testVariants.all { variant ->
        variant.connectedInstrumentTest.dependsOn tasks.named("startAdbDaemon")
    }
}

/**
 * It uses Gradle Plugin `com.github.hesch.execfork`
 * The task starts automatically, it is connected to androidTest lifecycle using line
 * `variant.connectedInstrumentTest.dependsOn tasks.named("startAdbDaemon")` above.
 * And the task finishes as soon as build is finished.
 */
tasks.register("startAdbDaemon", com.github.psxpaul.task.ExecFork) {
    executable = 'java'
    args = [ '-jar', './bin/adbserver-desktop.jar' ]
    workingDir = "$rootProject.rootDir"
}

And don't forget that adbserver-desktop.jar should be placed by the path: <root_project>/bin/adbserver-desktop.jar.

Do you think it worth having this sample in a Kaspresso doc?

ultraon commented 3 years ago

One important note - it works only for a build that is started by using gradle task connectedAndroidTest. By starting tests from AndroidStudio it doesn't work :-(

matzuk commented 3 years ago

Hi @ultraon! Sure, we thought about the simplifying of the AdbServer starting and how to make it as much transparent for a user as it is possible. But honestly, there is not a universal and simple solution here. The variant with Gradle is related to only connectedAndroidTest. I think that the execution of a jar file is easier than having a deal with Gradle, especially for beginners =)

AzamatCherchesov commented 1 year ago

We find this feature useful.

Requirements: 1) Create a new module at the root of the Kaspresso project and place all new code and plugin there. 2) Rewrite Kaspresso samples modules on a separate project to integrate the new plugin into existing tests 3) Rename allure-support and compose-support modules to match their maven names. 4) The new feature should be optional and easy to integrate (just by applying a plugin). 5) The plugin needs to know the correct path to adb. There must be a config block with a string argument ADB_PATH. If this argument is not passed, the fallback source must be android plugin 6) In a negative scenario, there should be understandable error log information. 7) Often we need to pull/push some files from/to device. That is why adb server should receive working dir as a string argument. If this argument is not passed, the fallback source must be project's root 8) All existing tests in the Kaspresso samples must use the new approach and be green. 9) Add a new page to our Kaspresso github wiki with details on how to use the new feature and how it works. 10) The supported version of Gradle + AGP - 7+