Skip to content

Instantly share code, notes, and snippets.

@k0siara
Created May 1, 2021 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0siara/a86f1aa58cf45f631dbec42e2b6e9b1a to your computer and use it in GitHub Desktop.
Save k0siara/a86f1aa58cf45f631dbec42e2b6e9b1a to your computer and use it in GitHub Desktop.
def appId = "com.patrykkosieradzki.moviebox"
android {
...
defaultConfig {
...
applicationId appId
}
}
def projectScreenshotsDirectory = "$projectDir/screenshots"
def deviceScreenshotsDirectory = '/sdcard/Pictures/' + appId + '/debug/screenshots'
def clearScreenshotsTask = task('clearScreenshots', type: Exec) {
println deviceScreenshotsDirectory
executable "${android.getAdbExe().toString()}"
args 'shell', 'rm', '-r', deviceScreenshotsDirectory
}
def createScreenshotDirectoryTask = task('createScreenshotDirectory', type: Exec, group: 'reporting') {
executable "${android.getAdbExe().toString()}"
args 'shell', 'mkdir', '-p', deviceScreenshotsDirectory
}
def fetchScreenshotsTask = task('fetchScreenshots', type: Exec, group: 'reporting') {
executable "${android.getAdbExe().toString()}"
args 'pull', deviceScreenshotsDirectory + '/.', projectScreenshotsDirectory
finalizedBy {
clearScreenshotsTask
}
dependsOn {
createScreenshotDirectoryTask
}
doFirst {
new File(projectScreenshotsDirectory).mkdirs()
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'connectedDebugAndroidTest') {
task.finalizedBy {
fetchScreenshotsTask
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment