Skip to content

Commit

Permalink
Add installApp command for IOS (mobile-dev-inc#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed Furkan Boran committed Aug 2, 2024
1 parent 6ed69d8 commit 37f4eb3
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion maestro-client/src/main/java/maestro/Driver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ interface Driver {

fun setAirplaneMode(enabled: Boolean)

fun installApk(apk: File)
fun installApp(path: String)
}
5 changes: 2 additions & 3 deletions maestro-client/src/main/java/maestro/Maestro.kt
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,8 @@ class Maestro(private val driver: Driver) : AutoCloseable {
driver.setAirplaneMode(enabled)
}

fun installApk(apkPath: String?) {
val apkFile = File(apkPath.orEmpty())
driver.installApk(apkFile)
fun installApp(path: String?) {
driver.installApp(path.orEmpty())
}

companion object {
Expand Down
5 changes: 3 additions & 2 deletions maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,9 @@ class AndroidDriver(
shell("cmd connectivity airplane-mode $value")
}

override fun installApk(apk: File) {
install(apk)
override fun installApp(path: String) {
val apkFile = File(path)
install(apkFile)
}


Expand Down
4 changes: 2 additions & 2 deletions maestro-client/src/main/java/maestro/drivers/IOSDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ class IOSDriver(
LOGGER.warn("Airplane mode is not available on iOS simulators")
}

override fun installApk(apk: File) {
LOGGER.warn("Install app is not available on iOS simulators")
override fun installApp(path: String) {
iosDevice.installApp(path)
}

private fun addMediaToDevice(mediaFile: File) {
Expand Down
2 changes: 1 addition & 1 deletion maestro-client/src/main/java/maestro/drivers/WebDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class WebDriver(val isStudio: Boolean) : Driver {
TODO("Not yet implemented")
}

override fun installApk(apk: File) {
override fun installApp(path: String) {
TODO("Not yet implemented")
}

Expand Down
12 changes: 12 additions & 0 deletions maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ object LocalSimulatorUtils {
)
}

fun install(deviceId: String, path: String) {
runCommand(
listOf(
"xcrun",
"simctl",
"install",
deviceId,
path,
)
)
}

fun uninstall(deviceId: String, bundleId: String) {
runCommand(
listOf(
Expand Down
2 changes: 2 additions & 0 deletions maestro-ios/src/main/java/ios/IOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ interface IOSDevice : AutoCloseable {
fun eraseText(charactersToErase: Int)

fun addMedia(path: String)

fun installApp(path: String)
}

interface IOSScreenRecording : AutoCloseable
4 changes: 4 additions & 0 deletions maestro-ios/src/main/java/ios/LocalIOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ class LocalIOSDevice(
override fun addMedia(path: String) {
simctlIOSDevice.addMedia(path)
}

override fun installApp(path: String) {
simctlIOSDevice.installApp(path)
}
}
7 changes: 7 additions & 0 deletions maestro-ios/src/main/java/ios/simctl/SimctlIOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,11 @@ class SimctlIOSDevice(
stopScreenRecording()
}

override fun installApp(path: String) {
LocalSimulatorUtils.install(
deviceId = deviceId,
path = path
)
}

}
4 changes: 4 additions & 0 deletions maestro-ios/src/main/java/ios/xctest/XCTestIOSDevice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ class XCTestIOSDevice(
execute { client.eraseText(charactersToErase, appIds) }
}

override fun installApp(path: String) {
error("Not supported")
}

private fun activeAppId(): String {
return execute {
val appIds = getInstalledApps()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,11 @@ data class ToggleAirplaneModeCommand(
}

data class InstallApplicationCommand(
val apkPath: String? = null,
val path: String? = null,
val label: String? = null,
): Command {
override fun description(): String {
return label ?: "Installing $apkPath"
return label ?: "Installing $path"
}

override fun evaluateScripts(jsEngine: JsEngine): Command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class Orchestra(
is AddMediaCommand -> addMediaCommand(command.mediaPaths)
is SetAirplaneModeCommand -> setAirplaneMode(command)
is ToggleAirplaneModeCommand -> toggleAirplaneMode()
is InstallApplicationCommand -> installApk(command)
is InstallApplicationCommand -> installApp(command)
else -> true
}.also { mutating ->
if (mutating) {
Expand All @@ -290,8 +290,8 @@ class Orchestra(
}
}

private fun installApk(command: InstallApplicationCommand): Boolean {
maestro.installApk(command.apkPath)
private fun installApp(command: InstallApplicationCommand): Boolean {
maestro.installApp(command.path)

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ data class YamlFluentCommand(
installApp != null -> listOf(
MaestroCommand(
InstallApplicationCommand(
apkPath = installApp.apkPath,
path = installApp.path,
label = installApp.label
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package maestro.orchestra.yaml
import com.fasterxml.jackson.annotation.JsonCreator

data class YamlInstallApp(
val apkPath: String? = null,
val path: String? = null,
val label: String? = null,
) {
companion object {
@JvmStatic
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
fun parse(apkPath: String) = YamlInstallApp(
apkPath = apkPath,
fun parse(path: String) = YamlInstallApp(
path = path,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class FakeDriver : Driver {
this.airplaneMode = enabled
}

override fun installApk(apk: File) {
override fun installApp(path: String) {
events.add(Event.InstallApp)
}

Expand Down

0 comments on commit 37f4eb3

Please sign in to comment.