Skip to content

Commit

Permalink
fix: optional commands in subFlow (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeetsingh150 authored Sep 30, 2024
1 parent c636dd7 commit 9b23967
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ data class TapOnElementCommand(
) : Command {

override fun description(): String {
return label ?: "${tapOnDescription(longPress, repeat)} on ${selector.description()}"
val optional = if (optional) "(Optional) " else ""
return label ?: "${tapOnDescription(longPress, repeat)} on $optional${selector.description()}"
}

override fun evaluateScripts(jsEngine: JsEngine): TapOnElementCommand {
Expand Down Expand Up @@ -379,7 +380,8 @@ data class AssertConditionCommand(
}

override fun description(): String {
return label ?: "Assert that ${condition.description()}"
val optional = if (optional) "(Optional) " else ""
return label ?: "Assert that $optional${condition.description()}"
}

override fun evaluateScripts(jsEngine: JsEngine): Command {
Expand Down
19 changes: 15 additions & 4 deletions maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,21 @@ class Orchestra(
updateMetadata(command, metadata)

return@mapIndexed try {
executeCommand(evaluatedCommand, config)
.also {
onCommandComplete(index, command)
}
try {
executeCommand(evaluatedCommand, config)
.also {
onCommandComplete(index, command)
}
} catch (exception: MaestroException) {
val isOptional = command.asCommand()?.optional == true
if (isOptional) throw CommandWarned(exception.message)
else throw exception
}
} catch (ignored: CommandWarned) {
// Swallow exception, but add a warning as an insight
Insights.report(Insight(message = ignored.message, level = Insight.Level.WARNING))
onCommandWarned(index, command)
false
} catch (ignored: CommandSkipped) {
// Swallow exception
onCommandSkipped(index, command)
Expand Down

0 comments on commit 9b23967

Please sign in to comment.