forked from mobile-dev-inc/Maestro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: launch arguments for Android (mobile-dev-inc#972)
- Loading branch information
1 parent
a2fb751
commit 3e55506
Showing
28 changed files
with
324 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
maestro-client/src/main/java/maestro/android/AndroidLaunchArguments.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package maestro.android | ||
|
||
import maestro_android.MaestroAndroid | ||
|
||
object AndroidLaunchArguments { | ||
|
||
fun Map<String, Any>.toAndroidLaunchArguments(): List<MaestroAndroid.ArgumentValue> { | ||
return toList().map { | ||
when (val value = it.second) { | ||
is Boolean -> MaestroAndroid.ArgumentValue.newBuilder() | ||
.setKey(it.first) | ||
.setValue(value.toString()) | ||
.setType(Boolean::class.java.name) | ||
.build() | ||
is Int -> MaestroAndroid.ArgumentValue.newBuilder() | ||
.setKey(it.first) | ||
.setValue(value.toString()) | ||
.setType(Int::class.java.name) | ||
.build() | ||
is Double -> MaestroAndroid.ArgumentValue.newBuilder() | ||
.setKey(it.first) | ||
.setValue(value.toString()) | ||
.setType(Double::class.java.name) | ||
.build() | ||
is String -> MaestroAndroid.ArgumentValue.newBuilder() | ||
.setKey(it.first) | ||
.setValue(value.toString()) | ||
.setType(String::class.java.name) | ||
.build() | ||
else -> MaestroAndroid.ArgumentValue.newBuilder() | ||
.setKey(it.first) | ||
.setValue(value.toString()) | ||
.setType(String::class.java.name) | ||
.build() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions
41
maestro-client/src/test/java/maestro/android/AndroidLaunchArgumentsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package maestro.android | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import maestro.android.AndroidLaunchArguments.toAndroidLaunchArguments | ||
import maestro_android.MaestroAndroid | ||
import org.junit.jupiter.api.Test | ||
|
||
class AndroidLaunchArgumentsTest { | ||
|
||
@Test | ||
fun `it correctly parses to android launch arguments`() { | ||
// given | ||
val arguments = mapOf<String, Any>( | ||
"isMaestro" to true, | ||
"cartValue" to 4, | ||
"cartValueDouble" to 4.4, | ||
"cartColor" to "Hello this is cart value which is orange" | ||
) | ||
|
||
// when | ||
val launchArguments = arguments.toAndroidLaunchArguments() | ||
|
||
// then | ||
assertThat(launchArguments).isEqualTo( | ||
listOf( | ||
provideArgumentValue("isMaestro", "true", Boolean::class.java.name), | ||
provideArgumentValue("cartValue", "4", Int::class.java.name), | ||
provideArgumentValue("cartValueDouble", "4.4", Double::class.java.name), | ||
provideArgumentValue("cartColor", "Hello this is cart value which is orange", String::class.java.name) | ||
) | ||
) | ||
} | ||
|
||
private fun provideArgumentValue(key: String, value: String, type: String): MaestroAndroid.ArgumentValue { | ||
return MaestroAndroid.ArgumentValue.newBuilder() | ||
.setKey(key) | ||
.setValue(value) | ||
.setType(type) | ||
.build() | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
maestro-ios-driver/src/main/kotlin/util/IOSLaunchArguments.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package util | ||
|
||
object IOSLaunchArguments { | ||
|
||
fun Map<String, Any>.toIOSLaunchArguments(): List<String> { | ||
if (isEmpty()) return emptyList() | ||
|
||
val iOSLaunchArgumentsMap = mutableMapOf<String, Any>() | ||
forEach { (key, value) -> | ||
if (value is Boolean) { | ||
iOSLaunchArgumentsMap[key] = value | ||
} else { | ||
if (!key.startsWith("-")) { | ||
iOSLaunchArgumentsMap["-$key"] = value | ||
} else { | ||
iOSLaunchArgumentsMap[key] = value | ||
} | ||
} | ||
} | ||
val iOSLaunchArguments = mutableListOf<String>() | ||
iOSLaunchArgumentsMap.toList().map { "${it.first}:${it.second}" } | ||
.forEach { | ||
iOSLaunchArguments += it.split(":") | ||
} | ||
|
||
return iOSLaunchArguments | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
maestro-ios-driver/src/test/kotlin/IOSLaunchArgumentsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.jupiter.api.Test | ||
import util.IOSLaunchArguments.toIOSLaunchArguments | ||
|
||
class IOSLaunchArgumentsTest { | ||
|
||
@Test | ||
fun `boolean params with one key are not touched`() { | ||
// given | ||
val launchArguments = mapOf("isCartScreen" to true) | ||
|
||
// when | ||
val iOSLaunchArguments = launchArguments.toIOSLaunchArguments() | ||
|
||
// then | ||
assertThat(iOSLaunchArguments).isEqualTo(listOf("isCartScreen", "true")) | ||
} | ||
|
||
@Test | ||
fun `key-value pair without prefixed '-' sign are transformed`() { | ||
// given | ||
val launchArguments = mapOf<String, Any>( | ||
"isCartScreen" to false, | ||
"cartValue" to 3 | ||
) | ||
|
||
// when | ||
val iOSLaunchArguments = launchArguments.toIOSLaunchArguments() | ||
|
||
// then | ||
assertThat(iOSLaunchArguments).isEqualTo(listOf("isCartScreen", "false", "-cartValue", "3")) | ||
} | ||
|
||
@Test | ||
fun `key-value pair with prefixed '-' sign are not changed`() { | ||
// given | ||
val launchArguments = mapOf<String, Any>( | ||
"isCartScreen" to false, | ||
"cartValue" to 3, | ||
"-cartColor" to "Orange" | ||
) | ||
|
||
// when | ||
val iOSLaunchArguments = launchArguments.toIOSLaunchArguments() | ||
|
||
// then | ||
assertThat(iOSLaunchArguments).isEqualTo( | ||
listOf("isCartScreen", "false", "-cartValue", "3", "-cartColor", "Orange") | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.