Skip to content

Commit

Permalink
fix: bring back removed optional for backward compatibility (#2079)
Browse files Browse the repository at this point in the history
* fix: bring back

* fix: handle in orchestra
  • Loading branch information
amanjeetsingh150 authored Oct 7, 2024
1 parent 7efc075 commit c52a031
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ data class ElementSelector(
val traits: List<ElementTrait>? = null,
val index: String? = null,
val enabled: Boolean? = null,
@Deprecated("This is a deprecated field, please use the optional in commands interface")
val optional: Boolean = false,
val selected: Boolean? = null,
val checked: Boolean? = null,
val focused: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ data class MaestroCommand(
else -> null
}

fun elementSelector(): ElementSelector? {
return when {
tapOnElement?.selector != null -> tapOnElement.selector
swipeCommand?.elementSelector != null -> swipeCommand.elementSelector
copyTextCommand?.selector != null -> copyTextCommand.selector
assertConditionCommand?.condition?.visible != null -> assertConditionCommand.condition.visible
assertConditionCommand?.condition?.notVisible != null -> assertConditionCommand.condition.notVisible
scrollUntilVisible?.selector != null -> scrollUntilVisible.selector
else -> null
}
}

fun evaluateScripts(jsEngine: JsEngine): MaestroCommand {
return asCommand()
?.let { MaestroCommand(it.evaluateScripts(jsEngine)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Orchestra(
executeCommand(evaluatedCommand, config)
onCommandComplete(index, command)
} catch (e: MaestroException) {
val isOptional = command.asCommand()?.optional == true
val isOptional = command.asCommand()?.optional == true || command.elementSelector()?.optional == true
if (isOptional) throw CommandWarned(e.message)
else throw e
}
Expand Down Expand Up @@ -684,7 +684,7 @@ class Orchestra(
onCommandComplete(index, command)
}
} catch (exception: MaestroException) {
val isOptional = command.asCommand()?.optional == true
val isOptional = command.asCommand()?.optional == true || command.elementSelector()?.optional == true
if (isOptional) throw CommandWarned(exception.message)
else throw exception
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ data class YamlFluentCommand(
textRegex = selector.text,
idRegex = selector.id,
size = size,
optional = selector.optional ?: false,
below = selector.below?.let { toElementSelector(it) },
above = selector.above?.let { toElementSelector(it) },
leftOf = selector.leftOf?.let { toElementSelector(it) },
Expand Down

0 comments on commit c52a031

Please sign in to comment.