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 eed7c3d390..1cc4b1f244 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt @@ -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 { @@ -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 { diff --git a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt index 33b68efaae..70d233e20e 100644 --- a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt +++ b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt @@ -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)