Skip to content

Commit 9b23967

Browse files
fix: optional commands in subFlow (#2071)
1 parent c636dd7 commit 9b23967

File tree

2 files changed

+19
-6
lines changed
  • maestro-orchestra/src/main/java/maestro/orchestra
  • maestro-orchestra-models/src/main/java/maestro/orchestra

2 files changed

+19
-6
lines changed

maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ data class TapOnElementCommand(
265265
) : Command {
266266

267267
override fun description(): String {
268-
return label ?: "${tapOnDescription(longPress, repeat)} on ${selector.description()}"
268+
val optional = if (optional) "(Optional) " else ""
269+
return label ?: "${tapOnDescription(longPress, repeat)} on $optional${selector.description()}"
269270
}
270271

271272
override fun evaluateScripts(jsEngine: JsEngine): TapOnElementCommand {
@@ -379,7 +380,8 @@ data class AssertConditionCommand(
379380
}
380381

381382
override fun description(): String {
382-
return label ?: "Assert that ${condition.description()}"
383+
val optional = if (optional) "(Optional) " else ""
384+
return label ?: "Assert that $optional${condition.description()}"
383385
}
384386

385387
override fun evaluateScripts(jsEngine: JsEngine): Command {

maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt

+15-4
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,21 @@ class Orchestra(
678678
updateMetadata(command, metadata)
679679

680680
return@mapIndexed try {
681-
executeCommand(evaluatedCommand, config)
682-
.also {
683-
onCommandComplete(index, command)
684-
}
681+
try {
682+
executeCommand(evaluatedCommand, config)
683+
.also {
684+
onCommandComplete(index, command)
685+
}
686+
} catch (exception: MaestroException) {
687+
val isOptional = command.asCommand()?.optional == true
688+
if (isOptional) throw CommandWarned(exception.message)
689+
else throw exception
690+
}
691+
} catch (ignored: CommandWarned) {
692+
// Swallow exception, but add a warning as an insight
693+
Insights.report(Insight(message = ignored.message, level = Insight.Level.WARNING))
694+
onCommandWarned(index, command)
695+
false
685696
} catch (ignored: CommandSkipped) {
686697
// Swallow exception
687698
onCommandSkipped(index, command)

0 commit comments

Comments
 (0)