Skip to content

Add DataFaker support #2341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Introduce DataFaker for existing random text commands, and add a few …
…more

Co-authored-by: Matheus <[email protected]>
  • Loading branch information
Fishbowler and Matheeusb committed Mar 2, 2025
commit 7a046efa66b056e0ee12f40b3191e89e85a98d88
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ commons-codec = "1.17.0"
commons-lang3 = "3.13.0" # 3.14.0 causes weird crashes during dexing
commons-io = "2.16.1"
dadb = "1.2.9"
datafaker = "1.9.0"
detekt = "1.19.0"
googleFindbugs = "3.0.2"
googleGson = "2.11.0"
Expand Down Expand Up @@ -68,6 +69,7 @@ commons-codec = { module = "commons-codec:commons-codec", version.ref = "commons
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang3" }
commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" }
dadb = { module = "dev.mobile:dadb", version.ref = "dadb" }
datafaker = { module = "net.datafaker:datafaker", version.ref = "datafaker" }
google-findbugs = { module = "com.google.code.findbugs:jsr305", version.ref = "googleFindbugs" }
google-gson = { module = "com.google.code.gson:gson", version.ref = "googleGson" }
google-protobuf-kotlin = { module = "com.google.protobuf:protobuf-kotlin", version.ref = "googleProtobuf" }
Expand Down
1 change: 1 addition & 0 deletions maestro-orchestra-models/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tasks.named("compileKotlin", KotlinCompilationTask::class.java) {

dependencies {
implementation(project(":maestro-client"))
implementation(libs.datafaker)

api(libs.jackson.core.databind)
api(libs.jackson.module.kotlin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import maestro.SwipeDirection
import maestro.TapRepeat
import maestro.js.JsEngine
import maestro.orchestra.util.Env.evaluateScripts
import maestro.orchestra.util.InputRandomTextHelper
import net.datafaker.Faker

sealed interface Command {

Expand Down Expand Up @@ -695,7 +695,13 @@ class ClearKeychainCommand(
}

enum class InputRandomType {
NUMBER, TEXT, TEXT_EMAIL_ADDRESS, TEXT_PERSON_NAME,
NUMBER,
TEXT,
TEXT_EMAIL_ADDRESS,
TEXT_PERSON_NAME,
TEXT_CITY_NAME,
TEXT_COUNTRY_NAME,
TEXT_COLOR,
}

data class InputRandomCommand(
Expand All @@ -706,15 +712,19 @@ data class InputRandomCommand(
) : Command {

fun genRandomString(): String {
val faker = Faker()
val lengthNonNull = length ?: 8
val finalLength = if (lengthNonNull <= 0) 8 else lengthNonNull

return when (inputType) {
InputRandomType.NUMBER -> InputRandomTextHelper.getRandomNumber(finalLength)
InputRandomType.TEXT -> InputRandomTextHelper.getRandomText(finalLength)
InputRandomType.TEXT_EMAIL_ADDRESS -> InputRandomTextHelper.randomEmail()
InputRandomType.TEXT_PERSON_NAME -> InputRandomTextHelper.randomPersonName()
else -> InputRandomTextHelper.getRandomText(finalLength)
InputRandomType.NUMBER -> faker.number().randomNumber(finalLength, false).toString()
InputRandomType.TEXT -> faker.text().text(finalLength)
InputRandomType.TEXT_EMAIL_ADDRESS -> faker.internet().emailAddress()
InputRandomType.TEXT_PERSON_NAME -> faker.name().name()
InputRandomType.TEXT_CITY_NAME -> faker.address().cityName()
InputRandomType.TEXT_COUNTRY_NAME -> faker.address().country()
InputRandomType.TEXT_COLOR -> faker.color().name()
else -> faker.text().text(finalLength)
}
}

Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions maestro-orchestra-models/src/test/kotlin/LitmusTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package maestro.orchestra

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test

class CommandsTest {

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

@Test
fun `should return not null value when call InputRandomCommand with TEXT value`() {
assertNotNull(InputRandomCommand(inputType = InputRandomType.TEXT).genRandomString())
}

@Test
fun `should return not null value when call InputRandomCommand with TEXT_EMAIL_ADDRESS value`() {
assertNotNull(InputRandomCommand(inputType = InputRandomType.TEXT_EMAIL_ADDRESS).genRandomString())
}

@Test
fun `should return not null value when call InputRandomCommand with TEXT_PERSON_NAME value`() {
assertNotNull(InputRandomCommand(inputType = InputRandomType.TEXT_PERSON_NAME).genRandomString())
}

@Test
fun `should return not null value when call InputRandomCommand with TEXT_CITY_NAME value`() {
assertNotNull(InputRandomCommand(inputType = InputRandomType.TEXT_CITY_NAME).genRandomString())
}

@Test
fun `should return not null value when call InputRandomCommand with TEXT_COUNTRY_NAME value`() {
assertNotNull(InputRandomCommand(inputType = InputRandomType.TEXT_COUNTRY_NAME).genRandomString())
}

@Test
fun `should return not null value when call InputRandomCommand with TEXT_COLOR value`() {
assertNotNull(InputRandomCommand(inputType = InputRandomType.TEXT_COLOR).genRandomString())
}

@Test
fun `should return not null value when call InputRandomCommand without inputType value`() {
assertNotNull(InputRandomCommand().genRandomString())
}

@Test
fun `should return a value with 10 characters when call InputRandomCommand with NUMBER value and length value`() {
assertEquals(10, InputRandomCommand(inputType = InputRandomType.NUMBER, length = 10).genRandomString().length)
}

@Test
fun `should return a value with 20 characters when call InputRandomCommand with TEXT value and length value`() {
assertEquals(20, InputRandomCommand(inputType = InputRandomType.TEXT, length = 20).genRandomString().length)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ data class YamlFluentCommand(
val inputRandomNumber: YamlInputRandomNumber? = null,
val inputRandomEmail: YamlInputRandomEmail? = null,
val inputRandomPersonName: YamlInputRandomPersonName? = null,
val inputRandomCityName: YamlInputRandomCityName? = null,
val inputRandomCountryName: YamlInputRandomCountryName? = null,
val inputRandomColorName: YamlInputRandomColorName? = null,
val launchApp: YamlLaunchApp? = null,
val swipe: YamlSwipe? = null,
val openLink: YamlOpenLink? = null,
Expand Down Expand Up @@ -202,59 +205,14 @@ data class YamlFluentCommand(
addMediaCommand = addMediaCommand(addMedia, flowPath)
)
)

inputText != null -> listOf(
MaestroCommand(
InputTextCommand(
text = inputText.text,
label = inputText.label,
optional = inputText.optional
)
)
)

inputRandomText != null -> listOf(
MaestroCommand(
InputRandomCommand(
inputType = InputRandomType.TEXT,
length = inputRandomText.length,
label = inputRandomText.label,
optional = inputRandomText.optional
)
)
)

inputRandomNumber != null -> listOf(
MaestroCommand(
InputRandomCommand(
inputType = InputRandomType.NUMBER,
length = inputRandomNumber.length,
label = inputRandomNumber.label,
optional = inputRandomNumber.optional
)
)
)

inputRandomEmail != null -> listOf(
MaestroCommand(
InputRandomCommand(
inputType = InputRandomType.TEXT_EMAIL_ADDRESS,
label = inputRandomEmail.label,
optional = inputRandomEmail.optional
)
)
)

inputRandomPersonName != null -> listOf(
MaestroCommand(
InputRandomCommand(
inputType = InputRandomType.TEXT_PERSON_NAME,
label = inputRandomPersonName.label,
optional = inputRandomPersonName.optional
)
)
)

inputText != null -> listOf(MaestroCommand(InputTextCommand(text = inputText.text, label = inputText.label, optional = inputText.optional)))
inputRandomText != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT, length = inputRandomText.length, label = inputRandomText.label, optional = inputRandomText.optional)))
inputRandomNumber != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.NUMBER, length = inputRandomNumber.length, label = inputRandomNumber.label, optional = inputRandomNumber.optional)))
inputRandomEmail != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT_EMAIL_ADDRESS, label = inputRandomEmail.label, optional = inputRandomEmail.optional)))
inputRandomPersonName != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT_PERSON_NAME, label = inputRandomPersonName.label, optional = inputRandomPersonName.optional)))
inputRandomCityName != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT_CITY_NAME, label = inputRandomCityName.label, optional = inputRandomCityName.optional)))
inputRandomCountryName != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT_COUNTRY_NAME, label = inputRandomCountryName.label, optional = inputRandomCountryName.optional)))
inputRandomColorName != null -> listOf(MaestroCommand(InputRandomCommand(inputType = InputRandomType.TEXT_COLOR, label = inputRandomColorName.label, optional = inputRandomColorName.optional)))
swipe != null -> listOf(swipeCommand(swipe))
openLink != null -> listOf(
MaestroCommand(
Expand Down Expand Up @@ -996,6 +954,18 @@ data class YamlFluentCommand(
inputRandomPersonName = YamlInputRandomPersonName(),
)

"inputRandomCityName" -> YamlFluentCommand(
inputRandomCityName = YamlInputRandomCityName(),
)

"inputRandomCountryName" -> YamlFluentCommand(
inputRandomCountryName = YamlInputRandomCountryName(),
)

"inputRandomColorName" -> YamlFluentCommand(
inputRandomColorName = YamlInputRandomColorName(),
)

"back" -> YamlFluentCommand(
back = YamlActionBack(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,18 @@ data class YamlInputRandomPersonName(
val label: String? = null,
val optional: Boolean = false,
)

data class YamlInputRandomCityName(
val label: String? = null,
val optional: Boolean = false,
)

data class YamlInputRandomCountryName(
val label: String? = null,
val optional: Boolean = false,
)

data class YamlInputRandomColorName(
val label: String? = null,
val optional: Boolean = false,
)