maestro.orchestra.util.Env.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.
package maestro.orchestra.util
import maestro.js.JsEngine
import maestro.orchestra.DefineVariablesCommand
import maestro.orchestra.MaestroCommand
object Env {
fun String.evaluateScripts(jsEngine: JsEngine): String {
val result = "(?
val script = match.groups[1]?.value ?: ""
if (script.isNotBlank()) {
jsEngine.evaluateScript(script).toString()
} else {
""
}
}
return result
.replace("\\\\\\\$\\{([^\$]*)}".toRegex()) { match ->
match.value.substringAfter('\\')
}
}
fun List.withEnv(env: Map): List {
if (env.isEmpty()) {
return this
}
return listOf(MaestroCommand(DefineVariablesCommand(env))) + this
}
}