maestro.orchestra.Condition.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maestro-orchestra-models Show documentation
Show all versions of maestro-orchestra-models Show documentation
Maestro is a server-driven platform-agnostic library that allows to drive tests for both iOS and Android using the same implementation through an intuitive API.
The newest version!
package maestro.orchestra
import maestro.Platform
import maestro.js.JsEngine
import maestro.orchestra.util.Env.evaluateScripts
data class Condition(
val platform: Platform? = null,
val visible: ElementSelector? = null,
val notVisible: ElementSelector? = null,
val scriptCondition: String? = null,
val label: String? = null,
) {
fun evaluateScripts(jsEngine: JsEngine): Condition {
return copy(
visible = visible?.evaluateScripts(jsEngine),
notVisible = notVisible?.evaluateScripts(jsEngine),
scriptCondition = scriptCondition?.evaluateScripts(jsEngine),
)
}
fun description(): String {
if(label != null){
return label
}
val descriptions = mutableListOf()
platform?.let {
descriptions.add("Platform is $it")
}
visible?.let {
descriptions.add("${it.description()} is visible")
}
notVisible?.let {
descriptions.add("${it.description()} is not visible")
}
scriptCondition?.let {
descriptions.add("$it is true")
}
return if (descriptions.isEmpty()) {
"true"
} else {
descriptions.joinToString(" and ")
}
}
}