Skip to content

Commit

Permalink
Merge branch 'main' into fix-labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishbowler authored Jun 3, 2024
2 parents 297256d + fc17954 commit 47a6bf6
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 0 deletions.
2 changes: 2 additions & 0 deletions maestro-client/src/main/java/maestro/Driver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface Driver {

fun stopApp(appId: String)

fun killApp(appId: String)

fun clearAppState(appId: String)

fun clearKeychain()
Expand Down
6 changes: 6 additions & 0 deletions maestro-client/src/main/java/maestro/Maestro.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class Maestro(private val driver: Driver) : AutoCloseable {
driver.stopApp(appId)
}

fun killApp(appId: String) {
LOGGER.info("Killing app $appId")

driver.killApp(appId)
}

fun clearAppState(appId: String) {
LOGGER.info("Clearing app state $appId")

Expand Down
5 changes: 5 additions & 0 deletions maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ class AndroidDriver(
shell("am force-stop $appId")
}

override fun killApp(appId: String) {
// Kill is the adb command needed to trigger System-initiated Process Death
shell("am kill $appId")
}

override fun clearAppState(appId: String) {
if (!isPackageInstalled(appId)) {
return
Expand Down
5 changes: 5 additions & 0 deletions maestro-client/src/main/java/maestro/drivers/IOSDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class IOSDriver(
iosDevice.stop(appId)
}

override fun killApp(appId: String) {
// On iOS there is no Process Death like on Android so this command will be a synonym to the stop command
stopApp(appId)
}

override fun clearAppState(appId: String) {
iosDevice.clearAppState(appId)
}
Expand Down
5 changes: 5 additions & 0 deletions maestro-client/src/main/java/maestro/drivers/WebDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class WebDriver(val isStudio: Boolean) : Driver {
driver.close()
}

override fun killApp(appId: String) {
// On Web there is no Process Death like on Android so this command will be a synonym to the stop command
stopApp(appId)
}

override fun contentDescriptor(excludeKeyboardElements: Boolean): TreeNode {
ensureOpen()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,22 @@ data class StopAppCommand(
}
}

data class KillAppCommand(
val appId: String,
val label: String? = null
) : Command {

override fun description(): String {
return label ?: "Kill $appId"
}

override fun evaluateScripts(jsEngine: JsEngine): Command {
return copy(
appId = appId.evaluateScripts(jsEngine),
)
}
}

data class ClearStateCommand(
val appId: String,
val label: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ data class MaestroCommand(
val hideKeyboardCommand: HideKeyboardCommand? = null,
val takeScreenshotCommand: TakeScreenshotCommand? = null,
val stopAppCommand: StopAppCommand? = null,
val killAppCommand: KillAppCommand? = null,
val clearStateCommand: ClearStateCommand? = null,
val clearKeychainCommand: ClearKeychainCommand? = null,
val runFlowCommand: RunFlowCommand? = null,
Expand Down Expand Up @@ -85,6 +86,7 @@ data class MaestroCommand(
hideKeyboardCommand = command as? HideKeyboardCommand,
takeScreenshotCommand = command as? TakeScreenshotCommand,
stopAppCommand = command as? StopAppCommand,
killAppCommand = command as? KillAppCommand,
clearStateCommand = command as? ClearStateCommand,
clearKeychainCommand = command as? ClearKeychainCommand,
runFlowCommand = command as? RunFlowCommand,
Expand Down Expand Up @@ -124,6 +126,7 @@ data class MaestroCommand(
hideKeyboardCommand != null -> hideKeyboardCommand
takeScreenshotCommand != null -> takeScreenshotCommand
stopAppCommand != null -> stopAppCommand
killAppCommand != null -> killAppCommand
clearStateCommand != null -> clearStateCommand
clearKeychainCommand != null -> clearKeychainCommand
runFlowCommand != null -> runFlowCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class Orchestra(
is EraseTextCommand -> eraseTextCommand(command)
is TakeScreenshotCommand -> takeScreenshotCommand(command)
is StopAppCommand -> stopAppCommand(command)
is KillAppCommand -> killAppCommand(command)
is ClearStateCommand -> clearAppStateCommand(command)
is ClearKeychainCommand -> clearKeychainCommand()
is RunFlowCommand -> runFlowCommand(command, config)
Expand Down Expand Up @@ -396,6 +397,12 @@ class Orchestra(
return true
}

private fun killAppCommand(command: KillAppCommand): Boolean {
maestro.killApp(command.appId)

return true
}

private fun scrollVerticalCommand(): Boolean {
maestro.scrollVertical()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ data class YamlFluentCommand(
val takeScreenshot: YamlTakeScreenshot? = null,
val extendedWaitUntil: YamlExtendedWaitUntil? = null,
val stopApp: YamlStopApp? = null,
val killApp: YamlKillApp? = null,
val clearState: YamlClearState? = null,
val runFlow: YamlRunFlow? = null,
val setLocation: YamlSetLocation? = null,
Expand Down Expand Up @@ -153,6 +154,14 @@ data class YamlFluentCommand(
)
)
)
killApp != null -> listOf(
MaestroCommand(
KillAppCommand(
appId = killApp.appId ?: appId,
label = killApp.label
)
)
)
clearState != null -> listOf(
MaestroCommand(
maestro.orchestra.ClearStateCommand(
Expand Down Expand Up @@ -617,6 +626,10 @@ data class YamlFluentCommand(
stopApp = YamlStopApp()
)

"killApp" -> YamlFluentCommand(
killApp = YamlKillApp()
)

"clearState" -> YamlFluentCommand(
clearState = YamlClearState(
appId = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package maestro.orchestra.yaml

import com.fasterxml.jackson.annotation.JsonCreator

data class YamlKillApp(
val appId: String? = null,
val label: String? = null,
) {

companion object {

@JvmStatic
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
fun parse(appId: String) = YamlKillApp(
appId = appId,
)

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,20 @@ internal class YamlCommandReaderTest {
)
}

@Test
fun killApp(
@YamlFile("025_killApp.yaml") commands: List<Command>,
) {
assertThat(commands).containsExactly(
ApplyConfigurationCommand(MaestroConfig(
appId = "com.example.app"
)),
KillAppCommand(
appId = "com.example.app"
),
)
}

private fun commands(vararg commands: Command): List<MaestroCommand> =
commands.map(::MaestroCommand).toList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appId: com.example.app
---
- killApp
10 changes: 10 additions & 0 deletions maestro-test/src/main/kotlin/maestro/test/drivers/FakeDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class FakeDriver : Driver {
events.add(Event.StopApp(appId))
}

override fun killApp(appId: String) {
ensureOpen()

events.add(Event.KillApp(appId))
}

override fun clearAppState(appId: String) {
ensureOpen()

Expand Down Expand Up @@ -431,6 +437,10 @@ class FakeDriver : Driver {
val appId: String
) : Event()

data class KillApp(
val appId: String
) : Event()

data class ClearState(
val appId: String
) : Event()
Expand Down
19 changes: 19 additions & 0 deletions maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3117,6 +3117,25 @@ class IntegrationTest {
orchestra(it).runFlow(commands)
}
}

@Test
fun `Case 116 - Kill app`() {
// Given
val commands = readCommands("115_kill_app")

val driver = driver {
}

// When
Maestro(driver).use {
orchestra(it).runFlow(commands)
}

// Then
// No test failure
driver.assertHasEvent(Event.KillApp("com.example.app"))
driver.assertHasEvent(Event.KillApp("another.app"))
}

private fun orchestra(
maestro: Maestro,
Expand Down
4 changes: 4 additions & 0 deletions maestro-test/src/test/resources/115_kill_app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
appId: com.example.app
---
- killApp
- killApp: another.app

0 comments on commit 47a6bf6

Please sign in to comment.