-
Notifications
You must be signed in to change notification settings - Fork 1
/
androidTests.gradle
73 lines (58 loc) · 2.63 KB
/
androidTests.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def reportsDirectory = "$buildDir/reports/androidTests/connected"
def embedScreenshotsTask = task('embedScreenshots', group: 'reporting') {
doFirst {
def failureScreenshotsDirectory = new File(reportsDirectory, 'screenshots/failures')
if (!failureScreenshotsDirectory.exists()) {
println 'Could not find screenshot failures. Skipping...'
return
}
failureScreenshotsDirectory.eachFile { failedTestClassDirectory ->
def failedTestClassName = failedTestClassDirectory.name
failedTestClassDirectory.eachFile { failedTestFile ->
def failedTestName = failedTestFile.name
def failedTestNameWithoutExtension = failedTestName.take(failedTestName.lastIndexOf('.'))
def failedTestClassJunitReportFile = new File(reportsDirectory, "${failedTestClassName}.html")
if (!failedTestClassJunitReportFile.exists()) {
println "Could not find JUnit report file for test class '${failedTestClassJunitReportFile}'"
return
}
def failedTestJunitReportContent = failedTestClassJunitReportFile.text
def patternToFind = "<h3 class=\"failures\">${failedTestNameWithoutExtension}</h3>"
def patternToReplace = "${patternToFind} <img src=\"screenshots/failures/${failedTestClassName}/${failedTestName}\" width =\"360\" />"
failedTestJunitReportContent = failedTestJunitReportContent.replaceAll(patternToFind, patternToReplace)
failedTestClassJunitReportFile.write(failedTestJunitReportContent)
}
}
}
}
def clearScreenshotsTask = task('clearScreenshots', type: Exec) {
executable "${android.getAdbExe().toString()}"
args 'shell', 'rm', '-r', '/sdcard/Pictures/my_app_folder'
finalizedBy {
embedScreenshotsTask
}
}
def createScreenshotDirectoryTask = task('createScreenshotDirectory', type: Exec, group: 'reporting') {
executable "${android.getAdbExe().toString()}"
args 'shell', 'mkdir', '-p', '/sdcard/Pictures/my_app_folder'
}
def fetchScreenshotsTask = task('fetchScreenshots', type: Exec, group: 'reporting') {
executable "${android.getAdbExe().toString()}"
args 'pull', '/sdcard/Pictures/my_app_folder/.', reportsDirectory
finalizedBy {
clearScreenshotsTask
}
dependsOn {
createScreenshotDirectoryTask
}
doFirst {
new File(reportsDirectory).mkdirs()
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'connectedDebugAndroidTest') {
task.finalizedBy {
fetchScreenshotsTask
}
}
}