From c60e781014f41a92a8b5d52876bdbff97bd98e62 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Mon, 16 Sep 2024 01:17:28 +0200 Subject: [PATCH 1/3] Fix issue with platform argument --- .../java/maestro/cli/command/TestCommand.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt index 58dfcb23ea..299f5e882f 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt @@ -61,6 +61,7 @@ import java.util.concurrent.Callable import java.util.concurrent.ConcurrentHashMap import kotlin.io.path.absolutePathString import kotlin.math.roundToInt +import maestro.cli.device.Platform @CommandLine.Command( name = "test", @@ -217,20 +218,22 @@ class TestCommand : Callable { val onlySequenceFlows = plan.sequence.flows.isNotEmpty() && plan.flowsToRun.isEmpty() // An edge case - val availableDevices = DeviceService.listConnectedDevices( - includeWeb = isWebFlow(), - host = parent?.host, - port = parent?.port, - ).map { it.instanceId }.toSet() + val connectedDevices = DeviceService.listConnectedDevices() + val availableDevicesIds = connectedDevices.map { it.instanceId }.toSet() + val deviceIds = getPassedOptionsDeviceIds() .filter { device -> - if (device !in availableDevices) { + if (device !in availableDevicesIds) { throw CliError("Device $device was requested, but it is not connected.") } else { true } } - .ifEmpty { availableDevices } + .ifEmpty { + connectedDevices + .filter { it.platform == Platform.fromString(parent?.platform) } + .map { it.instanceId }.toSet() + } .toList() val missingDevices = requestedShards - deviceIds.size @@ -293,7 +296,7 @@ class TestCommand : Callable { if (passed == total) 0 else 1 } - private suspend fun runShardSuite( + private fun runShardSuite( effectiveShards: Int, deviceIds: List, shardIndex: Int, From 3992919020c9e6b45c5a5c3346dc9f5532828a57 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Mon, 16 Sep 2024 01:19:29 +0200 Subject: [PATCH 2/3] Add test specific platform and device id commands --- .../main/java/maestro/cli/command/TestCommand.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt index 299f5e882f..21a22efce6 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt @@ -159,6 +159,15 @@ class TestCommand : Callable { ) private var headless: Boolean = false + @Option(names = ["-p", "--platform"], description = ["Select a platform to run on"]) + var platform: String? = null + + @Option( + names = ["--device", "--udid"], + description = ["Device ID to run on explicitly, can be a comma separated list of IDs: --device \"Emulator_1,Emulator_2\" "], + ) + var deviceId: String? = null + @CommandLine.Spec lateinit var commandSpec: CommandLine.Model.CommandSpec @@ -231,7 +240,7 @@ class TestCommand : Callable { } .ifEmpty { connectedDevices - .filter { it.platform == Platform.fromString(parent?.platform) } + .filter { it.platform == Platform.fromString(platform ?: parent?.platform) } .map { it.instanceId }.toSet() } .toList() @@ -313,8 +322,7 @@ class TestCommand : Callable { port = parent?.port, driverHostPort = driverHostPort, deviceId = deviceId, - platform = parent?.platform, - isHeadless = headless, + platform = platform ?: parent?.platform, ) { session -> val maestro = session.maestro val device = session.device @@ -433,7 +441,7 @@ class TestCommand : Callable { val arguments = if (isWebFlow()) { PrintUtils.warn("Web support is in Beta. We would appreciate your feedback!\n") "chromium" - } else parent?.deviceId + } else deviceId ?: parent?.deviceId val deviceIds = arguments .orEmpty() .split(",") From 95f80c9579334a05202ca3be4392bd11ea62a4e0 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Mon, 16 Sep 2024 03:25:23 +0200 Subject: [PATCH 3/3] Fix case no platform is specified --- maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt index 21a22efce6..52a435fe14 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt @@ -239,8 +239,9 @@ class TestCommand : Callable { } } .ifEmpty { + val platform = platform ?: parent?.platform connectedDevices - .filter { it.platform == Platform.fromString(platform ?: parent?.platform) } + .filter { platform == null || it.platform == Platform.fromString(platform) } .map { it.instanceId }.toSet() } .toList()