Skip to content

Commit

Permalink
Fix evaluate script bug mobile-dev-inc#1788
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed Furkan Boran committed Aug 31, 2024
1 parent 0cd8bc1 commit 5850f3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ data class SwipeCommand(
data class ScrollUntilVisibleCommand(
val selector: ElementSelector,
val direction: ScrollDirection,
val scrollDuration: Long,
val scrollDuration: String = DEFAULT_SCROLL_DURATION,
val visibilityPercentage: Int,
val timeout: Long = DEFAULT_TIMEOUT_IN_MILLIS,
val centerElement: Boolean,
Expand All @@ -104,19 +104,24 @@ data class ScrollUntilVisibleCommand(

val visibilityPercentageNormalized = (visibilityPercentage / 100).toDouble()

private fun String.speedToDuration(): String {
return ((1000 * (100 - this.toLong()).toDouble() / 100).toLong() + 1).toString()
}

override fun description(): String {
return label ?: "Scrolling $direction until ${selector.description()} is visible."
}

override fun evaluateScripts(jsEngine: JsEngine): ScrollUntilVisibleCommand {
return copy(
selector = selector.evaluateScripts(jsEngine),
scrollDuration = scrollDuration.evaluateScripts(jsEngine).speedToDuration()
)
}

companion object {
const val DEFAULT_TIMEOUT_IN_MILLIS = 20 * 1000L
const val DEFAULT_SCROLL_DURATION = 40
const val DEFAULT_SCROLL_DURATION = "40"
const val DEFAULT_ELEMENT_VISIBILITY_PERCENTAGE = 100
const val DEFAULT_CENTER_ELEMENT = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class Orchestra(
}
} catch (ignored: MaestroException.ElementNotFound) {
}
maestro.swipeFromCenter(direction, durationMs = command.scrollDuration)
maestro.swipeFromCenter(direction, durationMs = command.scrollDuration.toLong())
} while (System.currentTimeMillis() < endTime)

throw MaestroException.ElementNotFound(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ data class YamlFluentCommand(
selector = toElementSelector(yaml.element),
direction = yaml.direction,
timeout = timeout,
scrollDuration = yaml.speedToDuration(),
scrollDuration = yaml.speed,
visibilityPercentage = visibility,
centerElement = yaml.centerElement,
label = yaml.label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ data class YamlScrollUntilVisible(
val direction: ScrollDirection = ScrollDirection.DOWN,
val element: YamlElementSelectorUnion,
val timeout: Long = ScrollUntilVisibleCommand.DEFAULT_TIMEOUT_IN_MILLIS,
val speed: Int = ScrollUntilVisibleCommand.DEFAULT_SCROLL_DURATION,
val speed: String,
val visibilityPercentage: Int = ScrollUntilVisibleCommand.DEFAULT_ELEMENT_VISIBILITY_PERCENTAGE,
val centerElement: Boolean = ScrollUntilVisibleCommand.DEFAULT_CENTER_ELEMENT,
val label: String? = null
) {
fun speedToDuration(): Long {
return (1000 * (100 - speed).toDouble() / 100).toLong() + 1
}
}
)

0 comments on commit 5850f3d

Please sign in to comment.