All Downloads are FREE. Search and download functionalities are using the official Maven repository.

maestro.orchestra.util.Env.kt Maven / Gradle / Ivy

Go to download

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.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
    }

    fun Map.withInjectedShellEnvVars(): Map {
        val mutable = this.toMutableMap()
        val sysEnv = System.getenv()
        for (sysEnvKey in sysEnv.keys.filter { it.startsWith("MAESTRO_") }) {
            val sysEnvValue = sysEnv[sysEnvKey]
            if (mutable[sysEnvKey] == null && sysEnvValue != null) {
                mutable[sysEnvKey] = sysEnvValue
            }
        }

        return mutable
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy