Skip to content

Commit

Permalink
Improved way of passing params to process builder and added updated r…
Browse files Browse the repository at this point in the history
…eadme.
  • Loading branch information
przem-appunite committed Oct 16, 2018
1 parent 9e1f5ce commit d14847f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 27 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ firebaseTestLab {
// You can set timeout (in seconds) for test
// timeout = 6000
// Enable Android Test Orchestrator more info at: https://developer.android.com/training/testing/junit-runner
// isUseOrchestrator = true // default false
// A list of one or more test target filters to apply (default: run all test targets)
// testTargets = ["size large"]
// Environment variables are mirrored as extra options to the am instrument -e KEY1 VALUE1
// environmentVariables = ["clearPackageData=true", "coverage=true"]
// The fully-qualified Java class name of the instrumentation test runner
// testRunnerClass = "com.my.package.MyRunner"
// Pass any custom param for gcloud
// customParamsForGCloudTool = --no-performance-metrics
}
// You can define more devices
someOtherDevices {
Expand Down
2 changes: 1 addition & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: "maven"
apply plugin: "com.gradle.plugin-publish"

group = "firebase.test.lab"
version = "1.1.3-SNAPSHOT"
version = "1.1.5"


gradlePlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.appunite.firebasetestlabplugin.cloud
import com.appunite.firebasetestlabplugin.FirebaseTestLabPlugin
import com.appunite.firebasetestlabplugin.model.Device
import com.appunite.firebasetestlabplugin.model.TestResults
import com.appunite.firebasetestlabplugin.utils.asCommand
import com.appunite.firebasetestlabplugin.utils.joinArgs
import org.gradle.api.logging.Logger
import java.io.File
Expand Down Expand Up @@ -31,30 +30,31 @@ internal class FirebaseTestLabProcessCreator(
)

fun callFirebaseTestLab(device: Device, apk: File, testType: TestType): TestResults {
val type = when (testType) {
TestType.Robo -> "--type robo"
is TestType.Instrumentation -> "--type instrumentation --test ${testType.testApk}"
}

val processBuilder = ProcessBuilder("""
${sdk.gcloud.absolutePath}
firebase test android run
--format json
${if (gCloudBucketName != null) "--results-bucket $gCloudBucketName" else ""}
${if (gCloudDirectory != null) "--results-dir $gCloudDirectory" else ""}
$type
--locales ${device.locales.joinArgs()},
--os-version-ids ${device.androidApiLevels.joinArgs()}
--orientations ${device.screenOrientations.map { orientation -> orientation.gcloudName }.joinArgs()}
${if(device.isUseOrchestrator) "--use-orchestrator" else ""}
${if (device.environmentVariables.isNotEmpty()) "--environment-variables ${device.environmentVariables.joinToString(",")}" else ""}
${if (device.testTargets.isNotEmpty()) "--test-targets ${device.testTargets.joinToString(",", transform = { "\"$it\"" })}" else ""}
${device.customParamsForGCloudTool}
${device.testRunnerClass?.let { "--test-runner-class \"$it\"" } ?: ""}
--device-ids ${device .deviceIds.joinArgs()}
--app $apk
${if (device.timeout > 0) "--timeoutSec ${device.timeout}s" else ""}
""".asCommand())
val processBuilder = ProcessBuilder(
sequenceOf(
sdk.gcloud.absolutePath,
"firebase", "test", "android", "run",
"--format=json",
"--device-ids=${device.deviceIds.joinArgs()}",
"--app=$apk",
"--locales=${device.locales.joinArgs()}",
"--os-version-ids=${device.androidApiLevels.joinArgs()}",
"--orientations=${device.screenOrientations.map { orientation -> orientation.gcloudName }.joinArgs()}")
.plus(when (testType) {
TestType.Robo -> sequenceOf("--type=robo")
is TestType.Instrumentation -> sequenceOf("--type=instrumentation", "--test=${testType.testApk}")
})
.plus(gCloudBucketName?.let { sequenceOf("--results-bucket=$it") } ?: sequenceOf())
.plus(gCloudDirectory?.let { sequenceOf("--results-dir=$it") } ?: sequenceOf())
.plus(if (device.isUseOrchestrator) sequenceOf("--use-orchestrator") else sequenceOf())
.plus(if (device.environmentVariables.isNotEmpty()) sequenceOf("--environment-variables=${device.environmentVariables.joinToString(",")}") else sequenceOf())
.plus(if (device.testTargets.isNotEmpty()) sequenceOf("--test-targets=${device.testTargets.joinToString(",")}") else sequenceOf())
.plus(device.customParamsForGCloudTool)
.plus(device.testRunnerClass?.let { sequenceOf("--test-runner-class=$it") } ?: sequenceOf())
.plus(if (device.timeout > 0) sequenceOf("--timeoutSec=${device.timeout}s") else sequenceOf())
.toList()
)
logger.debug(processBuilder.command().joinToString(separator = " ", transform = { "\"$it\"" }))
val process = processBuilder.start()
process.errorStream.bufferedReader().forEachLine { logger.lifecycle(it) }
process.inputStream.bufferedReader().forEachLine { logger.lifecycle(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Device(val name: String) {
var abiSplits: Set<String> = setOf()
var isUseOrchestrator = false
var environmentVariables: List<String> = listOf()
var customParamsForGCloudTool: String = ""
var customParamsForGCloudTool: List<String> = listOf()
var testTargets: List<String> = listOf()
var testRunnerClass: String? = null
}
Expand Down

0 comments on commit d14847f

Please sign in to comment.