-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcucumber.gradle
104 lines (94 loc) · 3.42 KB
/
cucumber.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import groovyx.gpars.GParsPool
import net.masterthought.cucumber.ReportBuilder
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.codehaus.gpars:gpars:1.2.1"
classpath "net.masterthought:cucumber-reporting:3.12.0"
}
}
task cucumber() {
dependsOn assemble, compileTestGroovy
doLast {
List<String> deviceNames = parseDevices()
List<String> cucumberTags = parseTags()
if (deviceNames.size() < 2) {
single(deviceNames[0], cucumberTags)
} else {
parallel(deviceNames, cucumberTags)
}
generateReport()
}
}
void single(String deviceName, List<String> cucumberTags) {
lunchCucumberCli(deviceName, cucumberTags)
}
void parallel(List<String> devices, List<String> cucumberTags) {
GParsPool.withPool(3) {
devices.eachParallel { String deviceName ->
println "Created fork for: ${deviceName}"
lunchCucumberCli(deviceName, cucumberTags)
}
}
}
void lunchCucumberCli(String deviceName, List<String> cucumberTags) {
println "Running for: ${deviceName}"
List<String> cucumberArgs = []
cucumberArgs = ['--plugin', 'pretty', '--plugin', "json:${reporting.baseDir}/cucumber/${deviceName}.json",
'--plugin', "html:build/reports/cucumber-html-report-1", '--glue',
'src/cucumber/', 'src/test/groovy/', 'src/test/resources/', 'src/cucumber/features']
cucumberArgs.addAll(cucumberTags)
try {
javaexec {
jvmArgs = ["-Dgeb.env=${deviceName}",
"-Dosx=${System.getProperty("osx", "")}"]
main = "cucumber.api.cli.Main"
classpath = sourceSets.test.runtimeClasspath + sourceSets.main.runtimeClasspath
//+ configurations.cucumberRuntime
args = cucumberArgs
}
}
catch (Exception e) {
}
}
List<String> parseTags() {
List<String> result = []
if (project.hasProperty('tags')) {
project.tags.replace(' ', '').split('&').each {
result << '--tags '
result << it.replace('|', ',')
}
} else {
println "No tags selected. Running for all."
}
result << '--tags '
result << '~@ignore'
return result
}
List<String> parseDevices() {
List<String> result = []
if (project.hasProperty('device')) {
result = project.device.replace(' ', '').split(',')
} else {
println 'No devices detected.'
}
result
}
def generateReport() {
println "Tests completed. Generating report...."
File reportOutputDirectory = new File("${reporting.baseDir}/")
def jsonReports = fileTree(dir: "${reporting.baseDir}/cucumber/").include '**.json'.toString()
List<String> jsonReportFiles = new ArrayList<String>()
jsonReports.each { File file ->
jsonReportFiles.add("${reporting.baseDir}/cucumber/${file.name}".toString());
}
String title = "Basic Mobile Automation Report"
net.masterthought.cucumber.Configuration configuration = new net.masterthought.cucumber.Configuration(reportOutputDirectory, title)
configuration.setParallelTesting(true)
configuration.setRunWithJenkins(false)
configuration.setBuildNumber("1")
ReportBuilder reportBuilder = new ReportBuilder(jsonReportFiles, configuration)
reportBuilder.generateReports()
}