-
Notifications
You must be signed in to change notification settings - Fork 409
Adds shake command #2259
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
base: main
Are you sure you want to change the base?
Adds shake command #2259
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,6 +170,44 @@ class XCTestDriverClient( | |
installer.close() | ||
} | ||
|
||
fun shake(){ | ||
logger.trace("Executing shake gesture on iOS simulator") | ||
|
||
try { | ||
// Create ProcessBuilder for executing AppleScript | ||
val processBuilder = ProcessBuilder( | ||
"osascript", | ||
"-e", """ | ||
tell application "Simulator" | ||
activate | ||
delay 0.5 -- Give simulator time to come to foreground | ||
tell application "System Events" | ||
tell process "Simulator" | ||
-- Access the Hardware menu and click Shake Gesture | ||
click menu item "Shake" of menu "Device" of menu bar 1 | ||
end tell | ||
end tell | ||
end tell | ||
""".trimIndent() | ||
) | ||
|
||
// Execute the command | ||
val process = processBuilder.start() | ||
val exitCode = process.waitFor() | ||
|
||
if (exitCode != 0) { | ||
val errorStream = process.errorStream.bufferedReader().readText() | ||
logger.error("Failed to execute shake gesture. Exit code: $exitCode, Error: $errorStream") | ||
throw IOException("Failed to execute shake gesture on simulator. Exit code: $exitCode") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The catch block below will re-throw this with this message wrapped in the same message again: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review. 68212e0 |
||
} | ||
|
||
logger.trace("Successfully executed shake gesture") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now if exitCode != 0 you will log the error, but don't do anything about it and you'll log this 'Successful' message and return normally. Sorry I wasn't more clear in the earlier review. I'd suggest bringing the previous throw back, so the function exits properly on error. But something else needs to change to avoid the double message. I thought of two options.
|
||
} catch (e: Exception) { | ||
logger.error("Error executing shake gesture", e) | ||
throw XCUITestServerError.UnknownFailure("Failed to execute shake gesture on simulator: ${e.message}") | ||
} | ||
} | ||
|
||
fun setPermissions(permissions: Map<String, String>) { | ||
executeJsonRequest("setPermissions", SetPermissionsRequest(permissions)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package maestro.orchestra.yaml | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator | ||
|
||
data class YamlShake( | ||
val label: String? = null, | ||
val optional: Boolean = false, | ||
) { | ||
|
||
companion object { | ||
|
||
@JvmStatic | ||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING) | ||
fun parse() = YamlShake() | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
appId: com.example.app | ||
--- | ||
- shake |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
diff a/maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt b/maestro-test/src/test/kotlin/maestro/test/IntegrationTest.kt (rejected hunks) | ||
@@ -3279,6 +3279,24 @@ class IntegrationTest { | ||
assertThat(action).isEqualTo(targetAction) | ||
} | ||
|
||
+ @Test | ||
+ fun `Case 122 - Kill app`() { | ||
+ // Given | ||
+ val commands = readCommands("122_shake") | ||
+ | ||
+ val driver = driver { | ||
+ } | ||
+ | ||
+ // When | ||
+ Maestro(driver).use { | ||
+ orchestra(it).runFlow(commands) | ||
+ } | ||
+ | ||
+ // Then | ||
+ // No test failure | ||
+ driver.assertHasEvent(Event.Shake("com.example.app")) | ||
+ } | ||
+ | ||
private fun orchestra( | ||
maestro: Maestro, | ||
) = Orchestra( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
appId: com.example.app | ||
--- | ||
- shake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tested this?
I've seen something like this on a SO thread:
curious how we make sure this sort of function actually works