-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
199 lines (183 loc) · 6.84 KB
/
Copy pathbuild.gradle
File metadata and controls
199 lines (183 loc) · 6.84 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import org.gradle.api.tasks.testing.logging.TestLogEvent
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
plugins {
id 'idea'
id 'java'
id 'se.thinkcode.cucumber-runner' version '0.0.11'
id "com.github.spacialcircumstances.gradle-cucumber-reporting" version "0.1.25"
id 'io.qameta.allure' version '2.11.2'
}
group 'fifernandez.test'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.2"
testImplementation "io.cucumber:cucumber-java:7.15.0"
testImplementation "io.cucumber:cucumber-junit:7.15.0"
testImplementation "org.junit.vintage:junit-vintage-engine:5.10.2"
testImplementation "org.json:json:20231013"
testImplementation "com.googlecode.json-simple:json-simple:1.1.1"
testImplementation "io.rest-assured:rest-assured:5.4.0"
testImplementation "io.rest-assured:json-schema-validator:5.4.0"
testImplementation "commons-io:commons-io:2.15.1"
testImplementation "io.qameta.allure:allure-cucumber7-jvm:2.26.0"
testImplementation "com.github.automatedowl:allure-environment-writer:1.0.0"
testImplementation "org.slf4j:slf4j-simple:1.7.36"
}
task moveCategories(type: Copy) {
from "src/test/resources/categories.json"
into "build/allure-results/"
}
test {
finalizedBy moveCategories
systemProperty("cucumber.junit-platform.naming-strategy", "long")
systemProperty("cucumber.filter.tags", getTags())
systemProperty("allure.results.directory", "build/allure-results")
testLogging {
events TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED
}
systemProperties(project.gradle.startParameter.systemPropertiesArgs)
useJUnitPlatform()
}
allure {
version = '2.26.0'
}
cucumberReports {
outputDir = file('build/reports/')
buildId = '0'
reports = files('build/reports/cucumber.json')
excludeTags = ["@tmsLink=(|\\w+)", "@issue=(|\\w+)", "@dev", "@qa", "@stage", "@prod"]
expandAllSteps = false
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
cucumber {
main = 'io.cucumber.core.cli.Main'
tags = getTags()
plugin = [
"pretty",
"json:${reporting.baseDir}/cucumber.json",
"junit:${reporting.baseDir}/cucumber.xml",
"html:${reporting.baseDir}/cucumber-report.html",
"rerun:${reporting.baseDir}/rerun.txt",
"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"
]
}
tasks.cucumber {
finalizedBy generateCucumberReports, moveCategories
System.setProperty("allure.results.directory", "build/allure-results")
}
task runTests() {
dependsOn assemble, testClasses
finalizedBy generateCucumberReports//, moveCategories
doLast {
javaexec {
mainClass = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
if (System.getProperty("env") != null) {
systemProperty "env", System.getProperty("env")
}
if (System.getProperty("mode") != null) {
systemProperty "mode", System.getProperty("mode")
}
systemProperty "cucumber.filter.tags", getTags()
systemProperty "allure.results.directory", "build/allure-results"
if (System.getProperty("testRunID") != null) {
systemProperty "testRunID", System.getProperty("testRunID")
if (System.getProperty("jenkinsLink") != null) {
systemProperty "jenkinsLink", System.getProperty("jenkinsLink")
}
}
args = [
'--plugin', 'pretty',
'--plugin', "json:${reporting.baseDir}/cucumber.json",
'--plugin', "junit:${reporting.baseDir}/cucumber.xml",
'--plugin', "html:${reporting.baseDir}/cucumber-report.html",
'--plugin', "rerun:${reporting.baseDir}/rerun.txt",
'--plugin', "io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm",
'--glue', "src/test/resources/features",
'--glue', "support"
]
}
}
}
String getTags() {
def jsonFile = file("src/test/java/config/config.json")
def parsedJson = new JsonSlurper().parseText(jsonFile.text)
String defaultEnvironment = parsedJson.defaultEnvironment
List<String> environments = parsedJson.environments
String selectedEnv = System.getProperty("env")
String tags = ""
if (selectedEnv == null) {
tags = "@${defaultEnvironment}"
} else {
selectedEnv = selectedEnv.toLowerCase()
if (environments.contains(selectedEnv)) {
tags = "@${selectedEnv}"
} else {
tags = "@${defaultEnvironment}"
}
}
tags += " and not @disable"
if (System.getProperty("tags") != null) {
tags = "(" + tags + ") and (" + System.getProperty("tags") + ")"
}
return tags
}
static boolean isWantedTag(String tag) {
List<String> undesiredTags = [
"@local", "@dev", "@qa", "@stage", "@prod",
"@smoke", "@sanity", "@regression"
]
if ((!(tag in undesiredTags)) && (!tag.contains('tmsLink=')) && (!tag.contains('issue='))) {
return true
}
return false
}
tasks.register('modifyJsonReport') {
doLast {
println "Cleaning the Json report."
//This will clear all the undesired tags from the report
def jsonSlurper = new JsonSlurper()
def jsonReports = fileTree(dir: "${reporting.baseDir}/").include '**.json'.toString()
jsonReports.each { File file ->
def parsedJson = jsonSlurper.parseText(file.text)
parsedJson.each {
it.elements.each { def current ->
ArrayList tags = current.tags
ArrayList aux = tags.clone()
tags.clear()
for (i in 0..aux.size() - 1) {
if (isWantedTag((String) aux[i].name)) {
tags.add(aux[i])
}
}
}
ArrayList tags = it.tags
ArrayList aux = tags.clone()
tags.clear()
if (!aux.isEmpty()) {
for (i in 0..aux.size() - 1) {
if (isWantedTag((String) aux[i].name)) {
tags.add(aux[i])
}
}
}
}
def jsonOutput = new JsonOutput()
def json_str = jsonOutput.toJson(parsedJson)
def json_beauty = jsonOutput.prettyPrint(json_str)
file.write(json_beauty)
}
}
}
tasks.generateCucumberReports {
dependsOn modifyJsonReport
}