Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ import maestro.TapRepeat
import maestro.js.JsEngine
import maestro.orchestra.util.Env.evaluateScripts
import com.fasterxml.jackson.annotation.JsonIgnore
import maestro.MaestroException
import java.nio.file.Path
import net.datafaker.Faker

internal fun parseTimeoutMs(timeout: String): Long {
return try {
timeout.replace("_", "").toLong()
} catch (e: NumberFormatException) {
throw MaestroException.InvalidCommand("Invalid timeout value: '$timeout'. Timeout must be a number in milliseconds.")
}
}

sealed interface Command {

@get:JsonIgnore
Expand Down Expand Up @@ -141,7 +150,8 @@ data class ScrollUntilVisibleCommand(
}

private fun String.timeoutToMillis(): String {
return if (this.toLong() < 0) {
val millis = parseTimeoutMs(this)
return if (millis < 0) {
DEFAULT_TIMEOUT_IN_MILLIS
} else this
}
Expand Down Expand Up @@ -417,7 +427,7 @@ data class AssertConditionCommand(
) : Command {

fun timeoutMs(): Long? {
return timeout?.replace("_", "")?.toLong()
return timeout?.let { parseTimeoutMs(it) }
}

override val originalDescription: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package maestro.orchestra

import maestro.MaestroException
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test

class CommandsTest {

@Test
fun `timeoutMs should return null for null timeout, parse valid values with underscores, and throw on invalid`() {
assertNull(AssertConditionCommand(condition = Condition(), timeout = null).timeoutMs())
assertEquals(10000L, AssertConditionCommand(condition = Condition(), timeout = "10_000").timeoutMs())
assertThrows(MaestroException.InvalidCommand::class.java) {
AssertConditionCommand(condition = Condition(), timeout = "abc").timeoutMs()
}
}

@Test
fun `should return not null value when call InputRandomCommand with NUMBER value`() {
assertNotNull(InputRandomCommand(inputType = InputRandomType.NUMBER).genRandomString())
Expand Down
Loading