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 26, 2024
1 parent d663575 commit 882d3b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
6 changes: 6 additions & 0 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.FlowDebugMetadata
import maestro.cli.report.TestDebugReporter
Expand All @@ -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 {

Expand All @@ -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,
Expand Down Expand Up @@ -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) {
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 @@ -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) {
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 @@ -158,3 +159,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 882d3b6

Please sign in to comment.