Skip to content

Commit

Permalink
Remove screenshot pulling functionality (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
technoir42 authored Jun 21, 2024
1 parent e07de46 commit c9a7636
Show file tree
Hide file tree
Showing 16 changed files with 8 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data class FileConfiguration(
var flakinessStrategy: FlakinessStrategy?,
var retryStrategy: RetryStrategy?,
var filteringConfiguration: FilteringConfiguration?,
var pullScreenshotFilterConfiguration: FilteringConfiguration?,
var strictRunFilterConfiguration: StrictRunFilterConfiguration?,

var cache: CacheConfiguration?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class ConfigFactory(private val mapper: ObjectMapper) {
noDevicesTimeoutMillis = config.noDevicesTimeoutMillis,
debug = config.debug,
vendorConfiguration = vendorConfiguration as VendorConfiguration,
analyticsTracking = config.analyticsTracking,
pullScreenshotFilterConfiguration = config.pullScreenshotFilterConfiguration
analyticsTracking = config.analyticsTracking
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ class TestCacheLoader(
if (configuration.cache.isEnabled) {
val testCacheBlackList: MutableList<Test> = arrayListOf()
tests.tests.forEach { test ->
val isStrictRunTest = configuration.strictRunFilterConfiguration.filter.matches(test)
val isPullScreenshotTest = configuration.pullScreenshotFilterConfiguration.whitelist.any { it.matches(test) }
if (isStrictRunTest || isPullScreenshotTest) {
if (configuration.strictRunFilterConfiguration.filter.matches(test)) {
testCacheBlackList.add(test)
} else {
testsToCheck.send(TestToCheck(poolId, test, isStrictRun = false))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ data class Configuration constructor(
val flakinessStrategy: FlakinessStrategy,
val retryStrategy: RetryStrategy,
val filteringConfiguration: FilteringConfiguration,
val pullScreenshotFilterConfiguration: FilteringConfiguration,
val strictRunFilterConfiguration: StrictRunFilterConfiguration,
val listener: MarathonListener?,

Expand Down Expand Up @@ -73,7 +72,6 @@ data class Configuration constructor(
flakinessStrategy: FlakinessStrategy?,
retryStrategy: RetryStrategy?,
filteringConfiguration: FilteringConfiguration?,
pullScreenshotFilterConfiguration: FilteringConfiguration?,
strictRunFilterConfiguration: StrictRunFilterConfiguration?,
listener: MarathonListener?,

Expand Down Expand Up @@ -130,8 +128,7 @@ data class Configuration constructor(
noDevicesTimeoutMillis = noDevicesTimeoutMillis ?: DEFAULT_NO_DEVICES_TIMEOUT_MILLIS,
debug = debug ?: true,
vendorConfiguration = vendorConfiguration,
analyticsTracking = analyticsTracking ?: false,
pullScreenshotFilterConfiguration = pullScreenshotFilterConfiguration ?: FilteringConfiguration(emptyList(), emptyList())
analyticsTracking = analyticsTracking ?: false
)

fun toMap() =
Expand Down Expand Up @@ -160,7 +157,6 @@ data class Configuration constructor(
"noDevicesTimeoutMillis" to noDevicesTimeoutMillis.toString(),
"debug" to debug.toString(),
"vendorConfiguration" to vendorConfiguration.toString(),
"analyticsTracking" to analyticsTracking.toString(),
"pullScreenshotFilterConfiguration" to pullScreenshotFilterConfiguration.toString()
"analyticsTracking" to analyticsTracking.toString()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ private fun createConfiguration(
flakinessStrategy = extensionConfig.flakinessStrategy?.toStrategy(),
retryStrategy = extensionConfig.retryStrategy?.toStrategy(),
filteringConfiguration = extensionConfig.filteringConfiguration?.toFilteringConfiguration(),
pullScreenshotFilterConfiguration = extensionConfig.pullScreenshotFilterConfiguration?.toFilteringConfiguration(),
strictRunFilterConfiguration = extensionConfig.strictRunFilterConfiguration?.toStrictRunFilterConfiguration(),
cache = extensionConfig.cache?.toCacheConfiguration(),
ignoreFailures = extensionConfig.ignoreFailures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ open class MarathonExtension {
//Android specific for now
var autoGrantPermission: Boolean? = null
var instrumentationArgs: MutableMap<String, String> = mutableMapOf()
var pullScreenshotFilterConfiguration: FilteringPluginConfiguration? = null

//Kotlin way
fun cache(block: CachePluginConfiguration.() -> Unit) {
Expand Down Expand Up @@ -105,10 +104,6 @@ open class MarathonExtension {
instrumentationArgs = mutableMapOf<String, String>().also(block)
}

fun pullScreenshotFilterConfiguration(block: FilteringPluginConfiguration.() -> Unit) {
pullScreenshotFilterConfiguration = FilteringPluginConfiguration().also(block)
}

//Groovy way
fun cache(closure: Closure<*>) {
cache = CachePluginConfiguration()
Expand Down Expand Up @@ -164,12 +159,6 @@ open class MarathonExtension {
closure.call()
}

fun pullScreenshotFilterConfiguration(closure: Closure<*>) {
pullScreenshotFilterConfiguration = FilteringPluginConfiguration()
closure.delegate = pullScreenshotFilterConfiguration
closure.call()
}

fun strictRunFilter(closure: Closure<*>) {
strictRunFilterConfiguration = StrictRunFilterPluginConfiguration()
closure.delegate = strictRunFilterConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,22 @@ package com.malinskiy.marathon.android

import com.malinskiy.marathon.test.Test
import java.io.File
import java.io.IOException

class RemoteFileManager(private val device: AndroidDevice) {
private val tempDir = "/data/local/tmp"

fun pullFile(remoteFilePath: String, localFile: File) {
device.pullFile(remoteFilePath, localFile.absolutePath)
}

fun pullFromFilesDir(applicationId: String, remoteDir: String, localDir: File) {
val files = device.safeExecuteShellCommand(
command = "run-as $applicationId find $remoteDir -type f"
).trimIndent().lines()

if (files.isNotEmpty()) {
val archiveFile = localDir.resolve("$applicationId.tar.gz")
val remoteArchiveFile = "$tempDir/${archiveFile.name}"
device.executeCommand(
command = "touch $remoteArchiveFile",
errorMessage = "Failed to create empty file $remoteArchiveFile"
)
device.executeCommand(
command = "run-as $applicationId sh -c \"cd $remoteDir && tar -czf $remoteArchiveFile *\"",
errorMessage = "Failed to archive files"
)

device.pullFile(remoteArchiveFile, archiveFile.absolutePath)
device.executeCommand(
command = "rm $remoteArchiveFile",
errorMessage = "Failed to delete temporary file $remoteArchiveFile"
)

untar(archiveFile, localDir)
}
}

fun remove(remotePath: String) {
device.executeCommand(
command = "rm -r $remotePath",
errorMessage = "Failed to delete $remotePath"
)
}

fun removeFromFilesDir(applicationId: String, remotePath: String) {
device.executeCommand(
command = "run-as $applicationId rm -r $remotePath",
errorMessage = "Failed to delete $remotePath"
)
}

fun remoteVideoForTest(test: Test): String {
val fileName = "${test.pkg}.${test.clazz}-${test.method}.mp4"
return "${device.getExternalStorageMount()}/$fileName"
}

fun getScreenshotsDir(applicationId: String): String =
"${getFilesDir(applicationId)}/screenshots/default"

private fun getFilesDir(applicationId: String): String =
"/data/data/$applicationId/files"

private fun untar(archive: File, destination: File) {
val process = ProcessBuilder()
.command("tar", "-xzf", archive.absolutePath)
.directory(destination)
.start()
if (process.waitFor() != 0) {
throw IOException("Failed to extract archive $archive to $destination")
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class AndroidTestParserSpek : Spek(
applicationOutput = File(""),
testApplicationOutput = apkFile
),
analyticsTracking = false,
pullScreenshotFilterConfiguration = null
analyticsTracking = false
)
val componentInfo = AndroidComponentInfoExtractor().extract(configuration)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ class AndroidDeviceTestRunner(private val device: DdmlibAndroidDevice) {
val errorMessage = "adb error while running tests ${testBatch.tests.map { it.toTestName() }}"
logger.error(e) { errorMessage }
listener.testRunFailed(errorMessage)
} finally {

}
// Do not catch FailedToPullScreenshotsException. If that's thrown, we should fail the whole task
}

private fun notifyIgnoredTest(ignoredTests: List<Test>, listeners: ITestRunListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.malinskiy.marathon.android.executor.listeners.NoOpTestRunListener
import com.malinskiy.marathon.android.executor.listeners.ProgressTestRunListener
import com.malinskiy.marathon.android.executor.listeners.TestRunListener
import com.malinskiy.marathon.android.executor.listeners.TestRunResultsListener
import com.malinskiy.marathon.android.executor.listeners.pull.PullScreenshotTestRunListener
import com.malinskiy.marathon.android.executor.listeners.screenshot.ScreenCapturerTestRunListener
import com.malinskiy.marathon.android.executor.listeners.video.ScreenRecorderHandler
import com.malinskiy.marathon.android.executor.listeners.video.ScreenRecorderOptions
Expand Down Expand Up @@ -57,7 +56,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.newFixedThreadPoolContext
import kotlinx.coroutines.plus
import kotlinx.coroutines.runBlocking
import java.awt.image.BufferedImage
import java.io.IOException
Expand Down Expand Up @@ -322,18 +320,11 @@ class DdmlibAndroidDevice(
prepareRecorderListener(feature, attachmentProviders)
} ?: NoOpTestRunListener()

val pullScreenshotListener = if (configuration.isPullScreenshotEnabled()) {
createPullScreenshotTestRunListener(devicePoolId, configuration, testBatch)
} else {
NoOpTestRunListener()
}

return CompositeTestRunListener(
listOf(
recorderListener,
TestRunResultsListener(testBatch, this, deferred, timer, progressReporter, devicePoolId, strictRunChecker, attachmentProviders),
DebugTestRunListener(this),
pullScreenshotListener,
ProgressTestRunListener(this, devicePoolId, progressReporter)
)
)
Expand Down Expand Up @@ -363,23 +354,6 @@ class DdmlibAndroidDevice(
else -> null
}

private fun Configuration.isPullScreenshotEnabled(): Boolean =
pullScreenshotFilterConfiguration.whitelist.isNotEmpty()

private fun createPullScreenshotTestRunListener(
devicePoolId: DevicePoolId,
configuration: Configuration,
testBatch: TestBatch
): PullScreenshotTestRunListener =
PullScreenshotTestRunListener(
device = this,
devicePoolId = devicePoolId,
outputDir = configuration.outputDir,
pullScreenshotFilterConfiguration = configuration.pullScreenshotFilterConfiguration,
testBatch = testBatch,
coroutineScope = this + parentJob
)

override fun safeUninstallPackage(appPackage: String): String? {
return try {
ddmsDevice.safeUninstallPackage(appPackage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ class AndroidDeviceTestRunnerSpek : Spek(
testApplicationOutput = apkFile,
implementationModules = emptyList()
),
analyticsTracking = false,
pullScreenshotFilterConfiguration = null
analyticsTracking = false
)
val componentInfo = AndroidComponentInfoExtractor().extract(configuration)
val ignoredTest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ object DerivedDataManagerSpek : Spek(
debugSsh = false,
alwaysEraseSimulators = true
),
analyticsTracking = false,
pullScreenshotFilterConfiguration = null
analyticsTracking = false
)
val componentInfo = IOSComponentInfoExtractor().extract(configuration) as IOSComponentInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ object IOSTestParserSpek : Spek(
debugSsh = false,
alwaysEraseSimulators = true
),
analyticsTracking = false,
pullScreenshotFilterConfiguration = null
analyticsTracking = false
)
val iosComponentInfo = IOSComponentInfoExtractor().extract(configuration)

Expand Down
Loading

0 comments on commit c9a7636

Please sign in to comment.