Skip to content

Commit

Permalink
Fix description for appId
Browse files Browse the repository at this point in the history
  • Loading branch information
tokou committed Aug 30, 2024
1 parent 13cfbb5 commit 74a28da
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
8 changes: 6 additions & 2 deletions maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.FlowAIOutput
import maestro.cli.report.FlowDebugOutput
Expand All @@ -23,6 +24,7 @@ import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
import kotlin.concurrent.thread
import maestro.orchestra.withPlatformInAppId

/**
* Knows how to run a single Maestro flow (either one-shot or continuously).
Expand Down Expand Up @@ -51,13 +53,13 @@ object TestRunner {
)

val result = runCatching(resultView, maestro) {
val platform = device?.platform?.name?.let { Platform.fromString(it) }
val commands = YamlCommandReader.readCommands(flowFile.toPath())
.withEnv(env)

.withPlatformInAppId(platform)
YamlCommandReader.getConfig(commands)?.name?.let {
aiOutput = aiOutput.copy(flowName = it)
}

MaestroCommandRunner.runCommands(
maestro = maestro,
device = device,
Expand Down Expand Up @@ -106,9 +108,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) {
Expand Down
10 changes: 8 additions & 2 deletions maestro-client/src/main/java/maestro/Platform.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package maestro

enum class Platform {
ANDROID, IOS, WEB
}
ANDROID, IOS, WEB;

companion object {
fun fromString(p: String): Platform? {
return values().find { it.name.lowercase() == p.lowercase() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package maestro.orchestra

import maestro.Platform
import maestro.js.JsEngine

/**
Expand Down Expand Up @@ -164,3 +165,17 @@ data class MaestroCommand(
return asCommand()?.description() ?: "No op"
}
}

fun List<MaestroCommand>.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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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<MaestroAppId>() {

Expand Down

0 comments on commit 74a28da

Please sign in to comment.