Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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