简体   繁体   中英

Can Genymotion gradle plugin devices be launched in batches?

I have three devices defined in the genymotion section of my build.gradle :

apply plugin: "genymotion"

genymotion {

devices {
    "Google Nexus 5 - 5.1.0 - API 22 - 1080x1920" {
        template String.valueOf(it)
        deleteWhenFinish false
    }

    "Google Nexus 7 - 4.2.2 - API 17 - 800x1280" {
        template String.valueOf(it)
        deleteWhenFinish false
    }

    "Google Nexus 9 - 5.1.0 - API 22 - 2048x1536" {
        template String.valueOf(it)
        deleteWhenFinish false
    }
}

config {
    genymotionPath = "/Applications/Genymotion.app/Contents/MacOS/"
    taskLaunch = "connectedCheck"
    }
}

connectedCheck.dependsOn genymotionLaunch
connectedCheck.mustRunAfter genymotionLaunch
genymotionFinish.mustRunAfter connectedCheck

When I run ./gradlew connectedCheck all three are launched and tests ran on them simultaneously. If I wanted to add all devices that I'd like to test my app on, that list would grow to 20+ devices which my machine would not cope with. Therefore, I need a way to launch these tests in batches, of say 3. Is there a way to do this?

This can be achieved by creating productFlavors just for tests:

productFlavors {
    dev; // dev/smoke tests
    api18; api19; api21; // all api levels tests
}

These will produce separate test tasks that can be launched separately or in succession:

task allConnectedAndroidTests(type: GradleBuild) {
tasks = [
        'connectedApi18DebugAndroidTest',
        'connectedApi19DebugAndroidTest',
        'connectedApi21DebugAndroidTest'
    ]
}

Simply assign a buildFlavor to your one, or more devices:

"Google Nexus 5 - 5.1.0 - API 22 - 1080x1920" {
    template String.valueOf(it)
    productFlavors "api21"
}

"Google Nexus 7 - 4.2.2 - API 17 - 800x1280" {
    template String.valueOf(it)
    productFlavors "api18"
}

And when you launch one of the assigned launch tasks, only the assigned devices will be launched and have the tests ran on them. For example:

./gradlew allConnectedAndroidTests
...
<...>genymotionLaunchConnectedApi18DebugAndroidTest
<...>connectedApi18DebugAndroidTest
<...>genymotionFinishConnectedApi18DebugAndroidTest
...
<...>genymotionLaunchConnectedApi19DebugAndroidTest
<...>connectedApi19DebugAndroidTest
<...>genymotionFinishConnectedApi19DebugAndroidTest
...
<...>genymotionLaunchConnectedApi21DebugAndroidTest
<...>connectedApi21DebugAndroidTest
<...>genymotionFinishConnectedApi21DebugAndroidTest
...
BUILD SUCCESSFUL

Full source of this example: https://github.com/tomaszrykala/Genymotion-productFlavors/blob/master/app/build.gradle

According to Genymotion documentation:

How do I start a virtual device from a command prompt?

To start a virtual device from a command prompt:

  1. Retrieve the list of available virtual devices by running:

    • Windows: <Genymotion installer path>\\genyshell -c "devices list"

      Genymotion default installation path is C:\\Program Files\\Genymobile\\Genymotion.

    • Mac OS X: /Applications/Genymotion.app/Contents/MacOS/genyshell -c "devices list"

    • Linux: <Genymotion installer path>/genyshell -c "devices list"
  2. Start one of the virtual devices by running:

    • Windows: <Genymotion installer path>\\player --vm-name "<virtual device name>"
    • Mac OS X: /Applications/Genymotion.app/Contents/MacOS/player --vm-name "<virtual device name>"
    • Linux: <Genymotion installer path>/player --vm-name "<virtual device name>"

From: https://www.genymotion.com/#!/support?chapter=start-virtual-devices-command-prompt#faq

You can after checking list of devices, run a specific one, then test by Gradle plugin, after that using adb shutdown and run another:

Here's an example of running

./genyshell -c "devices list"

./genymotion/player --vm-name "Motorola Moto X - 4.4.4 - API 19 - 720x1280"

To kill emulator use:

pkill player

Hope it help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM