Skip to content

Commit

Permalink
[iOS] maestro record not working since 1.26.0 (#1042)
Browse files Browse the repository at this point in the history
* fix maestro record not working on iOS due to error=2, No such file or directory exception

* use script file contents inside ProcessBuilder and execute via bash -c

* revert removing comments
  • Loading branch information
artem888 committed May 3, 2023
1 parent 909bec8 commit 2bd380d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
37 changes: 23 additions & 14 deletions maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt
Expand Up @@ -411,23 +411,32 @@ object LocalSimulatorUtils {

fun startScreenRecording(deviceId: String): ScreenRecording {
val tempDir = createTempDirectory()
val script = LocalSimulatorUtils::class.java.getResource("/screenrecord.sh")!!.file
val recording = File(tempDir.toFile(), "screenrecording.mov")
val inputStream = LocalSimulatorUtils::class.java.getResourceAsStream("/screenrecord.sh")
if (inputStream != null) {
val recording = File(tempDir.toFile(), "screenrecording.mov")

val recordingProcess = ProcessBuilder(
listOf(
script,
deviceId,
recording.path
val processBuilder = ProcessBuilder(
listOf(
"bash",
"-c",
inputStream.bufferedReader().readText()
)
)
)
.redirectInput(PIPE)
.start()
val environment = processBuilder.environment()
environment["DEVICE_ID"] = deviceId
environment["RECORDING_PATH"] = recording.path

return ScreenRecording(
recordingProcess,
recording
)
val recordingProcess = processBuilder
.redirectInput(PIPE)
.start()

return ScreenRecording(
recordingProcess,
recording
)
} else {
throw IllegalStateException("screenrecord.sh file not found")
}
}

fun stopScreenRecording(screenRecording: ScreenRecording): File {
Expand Down
@@ -1,5 +1,3 @@
#!/usr/bin/env bash

# The `simctl recordVideo` command requires a SIGINT to be sent to stop the recording.
# Before the SIGINT is sent, the video file is not playable.
# Kotlin / JVM has no API to sent signals to subprocesses.
Expand All @@ -12,13 +10,8 @@
# Also not that the backend currently does not support hvec. That is why the
# codec is set to h264.

if [[ $# -ne 2 ]] ; then
echo 'Usage: screenrecord.sh <udid> <output file>'
exit 1
fi

echo "Start recording"
xcrun simctl io "$1" recordVideo --force --codec h264 "$2" &
xcrun simctl io "$DEVICE_ID" recordVideo --force --codec h264 "$RECORDING_PATH" &
simctlpid=$!

echo "Simctl pid $simctlpid"
Expand Down

0 comments on commit 2bd380d

Please sign in to comment.