diff --git a/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt b/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt index 81344c05b3..019812d84f 100644 --- a/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt +++ b/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt @@ -7,6 +7,7 @@ import com.github.michaelbull.result.get import com.github.michaelbull.result.getOr import com.github.michaelbull.result.onFailure import maestro.Maestro +import maestro.Platform import maestro.cli.device.Device import maestro.cli.report.FlowDebugMetadata import maestro.cli.report.TestDebugReporter @@ -22,6 +23,7 @@ import org.slf4j.LoggerFactory import java.io.File import java.nio.file.Path import kotlin.concurrent.thread +import maestro.orchestra.withPlatformInAppId object TestRunner { @@ -40,8 +42,10 @@ object TestRunner { val debug = FlowDebugMetadata() val result = runCatching(resultView, maestro) { + val platform = device?.platform?.name?.let { Platform.fromString(it) } val commands = YamlCommandReader.readCommands(flowFile.toPath()) .withEnv(env) + .withPlatformInAppId(platform) MaestroCommandRunner.runCommands( maestro, device, @@ -77,9 +81,11 @@ object TestRunner { join() } + val platform = device?.platform?.name?.let { Platform.fromString(it) } val commands = YamlCommandReader .readCommands(flowFile.toPath()) .withEnv(env) + .withPlatformInAppId(platform) // Restart the flow if anything has changed if (commands != previousCommands) { diff --git a/maestro-client/src/main/java/maestro/Platform.kt b/maestro-client/src/main/java/maestro/Platform.kt index 73bed1848e..8137080902 100644 --- a/maestro-client/src/main/java/maestro/Platform.kt +++ b/maestro-client/src/main/java/maestro/Platform.kt @@ -1,5 +1,11 @@ package maestro enum class Platform { - ANDROID, IOS, WEB -} \ No newline at end of file + ANDROID, IOS, WEB; + + companion object { + fun fromString(p: String): Platform? { + return values().find { it.name.lowercase() == p.lowercase() } + } + } +} diff --git a/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt b/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt index 0cb6419d0c..2ebcad8796 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt @@ -396,9 +396,9 @@ data class LaunchAppCommand( } var result = if (clearState != true) { - "Launch app \"$appId\"" + "Launch app \"${appId.description()}\"" } else { - "Launch app \"$appId\" with clear state" + "Launch app \"${appId.description()}\" with clear state" } if (clearKeychain == true) { diff --git a/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroCommand.kt b/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroCommand.kt index 3d4fc439d4..fe1d70aa20 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroCommand.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroCommand.kt @@ -19,6 +19,7 @@ package maestro.orchestra +import maestro.Platform import maestro.js.JsEngine /** @@ -158,3 +159,17 @@ data class MaestroCommand( return asCommand()?.description() ?: "No op" } } + +fun List.withPlatformInAppId(platform: Platform?) = if (platform == null) this else map { + when (val c = it.asCommand()) { + is LaunchAppCommand -> MaestroCommand(c.copy(appId = c.appId.copy(platform = platform))) + is KillAppCommand -> MaestroCommand(c.copy(appId = c.appId.copy(platform = platform))) + is StopAppCommand -> MaestroCommand(c.copy(appId = c.appId.copy(platform = platform))) + is ClearStateCommand -> MaestroCommand(c.copy(appId = c.appId.copy(platform = platform))) + is RunFlowCommand -> + MaestroCommand(c.copy(config = c.config?.copy(appId = c.config.appId?.copy(platform = platform)))) + is ApplyConfigurationCommand -> + MaestroCommand(c.copy(config = c.config.copy(appId = c.config.appId?.copy(platform = platform)))) + else -> it + } +} diff --git a/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroConfig.kt b/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroConfig.kt index 735de14e58..cf133329d2 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroConfig.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/MaestroConfig.kt @@ -36,6 +36,7 @@ data class MaestroAppId( val android: String?, val ios: String?, val web: String?, + private val platform: Platform? = null, ) { constructor(appId: String) : this(appId, appId, appId) @@ -45,13 +46,19 @@ data class MaestroAppId( Platform.WEB -> web ?: error("No appId specified for web.") } - fun evaluateScripts(jsEngine: JsEngine): MaestroAppId { - return copy( - android = android?.evaluateScripts(jsEngine), - ios = ios?.evaluateScripts(jsEngine), - web = web?.evaluateScripts(jsEngine), - ) - } + fun evaluateScripts(jsEngine: JsEngine) = copy( + android = android?.evaluateScripts(jsEngine), + ios = ios?.evaluateScripts(jsEngine), + web = web?.evaluateScripts(jsEngine), + ) + + fun description() = + if (listOfNotNull(android, ios, web).toSet().size == 1) listOfNotNull(android, ios, web).first() + else if (platform != null) forPlatform(platform) + else listOf("android", "ios", "web") + .zip(listOf(android, ios, web)) + .filter { it.second != null } + .joinToString(", ") { "${it.first}: ${it.second}" } class Deserializer : JsonDeserializer() {