diff --git a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt index 33b68efaae..eb07ff9bdc 100644 --- a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt +++ b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt @@ -599,6 +599,30 @@ class Orchestra( } } + condition.scriptCondition?.let { value -> + // Note that script should have been already evaluated by this point + + if (value.isBlank()) { + return false + } + + if (value.equals("false", ignoreCase = true)) { + return false + } + + if (value == "undefined") { + return false + } + + if (value == "null") { + return false + } + + if (value.toDoubleOrNull() == 0.0) { + return false + } + } + condition.visible?.let { try { findElement( @@ -635,30 +659,6 @@ class Orchestra( } } - condition.scriptCondition?.let { value -> - // Note that script should have been already evaluated by this point - - if (value.isBlank()) { - return false - } - - if (value.equals("false", ignoreCase = true)) { - return false - } - - if (value == "undefined") { - return false - } - - if (value == "null") { - return false - } - - if (value.toDoubleOrNull() == 0.0) { - return false - } - } - return true } diff --git a/maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt b/maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt index 9c95ca4d68..97cce4226c 100644 --- a/maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt +++ b/maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt @@ -2650,6 +2650,33 @@ class IntegrationTest { ).inOrder() } + @Test + fun `Case 098 - Execute conditions eagerly`() { + // Given + val commands = readCommands("098_runscript_conditionals_eager") + + // 'Click me' is not present in the view hierarchy + val driver = driver {} + + val receivedLogs = mutableListOf() + + // When + Maestro(driver).use { + orchestra( + maestro = it, + onCommandMetadataUpdate = { _, metadata -> + receivedLogs += metadata.logMessages + } + ).runFlow(commands) + } + + // Then + // test completes + driver.assertEvents(emptyList()) + // and script did not run + assertThat(receivedLogs).isEmpty() + } + @Test fun `Case 099 - Screen recording`() { // Given diff --git a/maestro-test/src/test/resources/098_runscript_conditionals_eager.yaml b/maestro-test/src/test/resources/098_runscript_conditionals_eager.yaml new file mode 100644 index 0000000000..6dd594dfec --- /dev/null +++ b/maestro-test/src/test/resources/098_runscript_conditionals_eager.yaml @@ -0,0 +1,7 @@ +appId: com.other.app +--- +- runScript: + when: + true: ${ 1 + 1 != 2 } + visible: Click me + file: 098_runScript.js