From 759d954dcea666af37b3f9a6c729ba6e92b4a0ba Mon Sep 17 00:00:00 2001 From: Vibin reddy Date: Sat, 9 Nov 2024 16:30:01 -0500 Subject: [PATCH] Fix timeout unit in ScrollUntilVisibleCommand (#2112) * Fix timeout unit in ScrollUntilVisibleCommand The `timeout` in ScrollUntilVisibleCommand should be interpreted as milliseconds: https://maestro.mobile.dev/api-reference/commands/scrolluntilvisible Fixes https://github.com/mobile-dev-inc/maestro/issues/2108. This was broken by https://github.com/mobile-dev-inc/maestro/pull/2023. --- .../demo_app/scrollUntilVisible_timeout.yaml | 13 +++++++++++++ .../src/main/java/maestro/orchestra/Commands.kt | 5 ++--- .../maestro/orchestra/yaml/YamlCommandReaderTest.kt | 2 +- .../resources/117_scroll_until_visible_speed.js | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 e2e/workspaces/demo_app/scrollUntilVisible_timeout.yaml diff --git a/e2e/workspaces/demo_app/scrollUntilVisible_timeout.yaml b/e2e/workspaces/demo_app/scrollUntilVisible_timeout.yaml new file mode 100644 index 0000000000..41cdb74ea4 --- /dev/null +++ b/e2e/workspaces/demo_app/scrollUntilVisible_timeout.yaml @@ -0,0 +1,13 @@ +appId: com.example.example +tags: + - passing +--- +- launchApp: + clearState: true +- evalScript: ${maestro.startTime = new Date()} +- scrollUntilVisible: + element: non-existent + timeout: 1000 + optional: true +- evalScript: ${maestro.endTime = new Date()} +- assertTrue: ${maestro.endTime - maestro.startTime < 5000} # Far less than the 20000 default, but enough to allow for processing time diff --git a/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt b/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt index 9c59306b48..3656ce3d50 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/Commands.kt @@ -115,8 +115,7 @@ data class ScrollUntilVisibleCommand( } private fun String.timeoutToMillis(): String { - val timeout = if (this.toLong() < 0) { DEFAULT_TIMEOUT_IN_MILLIS.toLong() * 1000L } else this.toLong() * 1000L - return timeout.toString() + return if (this.toLong() < 0) { DEFAULT_TIMEOUT_IN_MILLIS } else this } override fun description(): String { @@ -132,7 +131,7 @@ data class ScrollUntilVisibleCommand( } companion object { - const val DEFAULT_TIMEOUT_IN_MILLIS = "20" + const val DEFAULT_TIMEOUT_IN_MILLIS = "20000" const val DEFAULT_SCROLL_DURATION = "40" const val DEFAULT_ELEMENT_VISIBILITY_PERCENTAGE = 100 const val DEFAULT_CENTER_ELEMENT = false diff --git a/maestro-orchestra/src/test/java/maestro/orchestra/yaml/YamlCommandReaderTest.kt b/maestro-orchestra/src/test/java/maestro/orchestra/yaml/YamlCommandReaderTest.kt index 19db099240..2e20c03f93 100644 --- a/maestro-orchestra/src/test/java/maestro/orchestra/yaml/YamlCommandReaderTest.kt +++ b/maestro-orchestra/src/test/java/maestro/orchestra/yaml/YamlCommandReaderTest.kt @@ -433,7 +433,7 @@ internal class YamlCommandReaderTest { ScrollUntilVisibleCommand( selector = ElementSelector(textRegex = "Footer"), direction = ScrollDirection.DOWN, - timeout = "20", + timeout = "20000", scrollDuration = "40", visibilityPercentage = 100, label = "Scroll to the bottom", diff --git a/maestro-test/src/test/resources/117_scroll_until_visible_speed.js b/maestro-test/src/test/resources/117_scroll_until_visible_speed.js index cca0b994ac..9fdd6f6756 100644 --- a/maestro-test/src/test/resources/117_scroll_until_visible_speed.js +++ b/maestro-test/src/test/resources/117_scroll_until_visible_speed.js @@ -3,9 +3,9 @@ output.speed = { } output.timeout = { - slow: 20 + slow: 20000 } output.element = { id: "maestro" -} \ No newline at end of file +}