-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add screen record for last fail. Also fix test file pulling logic. (#10)
* Add screen record for last fail. Also fix test file pulling logic. * Rename video file name. Add more clear null file name message. Remove unnecessary coroutine launch. * Promote version to release.
- Loading branch information
Showing
11 changed files
with
275 additions
and
70 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
69 changes: 69 additions & 0 deletions
69
torque-core/src/main/kotlin/com/workday/torque/ScreenRecorder.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,69 @@ | ||
package com.workday.torque | ||
|
||
import com.gojuno.commander.os.Notification | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.rx2.await | ||
import java.io.File | ||
|
||
class ScreenRecorder(private val adbDevice: AdbDevice, | ||
args: Args, | ||
private val processRunner: ProcessRunner = ProcessRunner()) { | ||
private val videosDir = File(File(args.testFilesPullDeviceDirectory, "videos"), adbDevice.id) | ||
private val timeoutSeconds = args.chunkTimeoutSeconds | ||
private var videoRecordJob: Job? = null | ||
private var videoFileName: File? = null | ||
|
||
suspend fun start(coroutineScope: CoroutineScope, testDetails: TestDetails) { | ||
videoRecordJob = coroutineScope.launch { startRecordTestRun(testDetails) } | ||
} | ||
|
||
private suspend fun startRecordTestRun(testDetails: TestDetails) { | ||
videoFileName = getVideoFile(testDetails) | ||
|
||
processRunner.runAdb(commandAndArgs = listOf( | ||
"-s", adbDevice.id, | ||
"shell", "mkdir -p ${videoFileName!!.parentFile}" | ||
), | ||
destroyOnUnsubscribe = true) | ||
.ofType(Notification.Exit::class.java) | ||
.map { true } | ||
.doOnError { error -> adbDevice.log("Failed to mkdir on ${adbDevice.tag}, filepath: ${videoFileName!!.parentFile}, failed: $error") } | ||
.ignoreElements() | ||
.await() | ||
|
||
processRunner.runAdb(commandAndArgs = listOf( | ||
"-s", adbDevice.id, | ||
"shell", "screenrecord $videoFileName --time-limit $timeoutSeconds --size 720x1440" | ||
), | ||
destroyOnUnsubscribe = true) | ||
.ofType(Notification.Exit::class.java) | ||
.map { true } | ||
.doOnSubscribe { adbDevice.log("Started recording on ${adbDevice.tag}, filename: $videoFileName") } | ||
.doOnComplete { adbDevice.log("Ended recording on ${adbDevice.tag}, filename: $videoFileName") } | ||
.doOnError { error -> adbDevice.log("Failed to record on ${adbDevice.tag}, filename: $videoFileName, failed: $error") } | ||
.ignoreElements() | ||
.await() | ||
} | ||
|
||
private fun getVideoFile(testDetails: TestDetails): File { | ||
val testFolder = File(File(videosDir, testDetails.testClass), testDetails.testName) | ||
return File(testFolder, "test_recording.mp4") | ||
} | ||
|
||
fun stop() = videoRecordJob?.cancel() | ||
|
||
suspend fun removeLastFile() { | ||
checkNotNull(videoFileName) { "Filename cannot be null, must call start() first" } | ||
processRunner.runAdb(commandAndArgs = listOf( | ||
"-s", adbDevice.id, | ||
"shell", "rm $videoFileName" | ||
), | ||
destroyOnUnsubscribe = true) | ||
.ofType(Notification.Exit::class.java) | ||
.map { true } | ||
.ignoreElements() | ||
.await() | ||
} | ||
} |
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
Oops, something went wrong.