我正在通过gradle执行Cucumber自动化测试脚本,尽管我能够成功执行测试,但未生成报告。我确实尝试了以下gradle任务 一次一个。
下面复制了黄瓜gradle任务
a)对于下面的gradle任务,我能够执行不生成报告的脚本,因为我没有在args中包含reports语句
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty',
'--glue','com.inspire.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '@Api'
]
}
}
}
b)我试图包括与报告相关的几条语句,如下面的gradle任务所示,但由于出现异常而失败
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', 'json:target/InspireBrands.json', 'com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:',
'--monochrome', 'true',
'--features','src\test\resources\featurefile',
'--glue','com.inspire.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '@Api'
]
}
}
}
在1秒钟内成功完成 6个可执行的任务:6个最新任务 E:\ GradleProj_workspace \ GadleDemoProj>将黄瓜分级
配置项目:
http://product-api-qa.qa.dp-prv.inspirebrands.eastus.cloudapp.azure.com
http://product-api-qa.qa.dp-prv.inspirebrands.eastus.cloudapp.azure.com
E:\GradleProj_workspace\GadleDemoProj
任务:黄瓜失败
Exception in thread "main" java.lang.IllegalArgumentException: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter: is not valid. Try URI[:LINE]*
at io.cucumber.core.model.FeatureWithLines.parse(FeatureWithLines.java:56)
at io.cucumber.core.options.RuntimeOptionsParser.parse(RuntimeOptionsParser.java:131)
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:25)
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:29)
at io.cucumber.core.cli.Main.run(Main.java:29)
at io.cucumber.core.cli.Main.main(Main.java:14)
Caused by: java.lang.IllegalArgumentException: Expected scheme-specific part at index 68: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:
at java.net.URI.create(URI.java:852)
at io.cucumber.core.model.FeaturePath.parseProbableURI(FeaturePath.java:72)
at io.cucumber.core.model.FeaturePath.parse(FeaturePath.java:57)
at io.cucumber.core.model.FeatureWithLines.parseFeaturePath(FeatureWithLines.java:77)
at io.cucumber.core.model.FeatureWithLines.parse(FeatureWithLines.java:53)
... 5 more
Caused by: java.net.URISyntaxException: Expected scheme-specific part at index 68: com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.failExpecting(URI.java:2854)
at java.net.URI$Parser.parse(URI.java:3057)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 9 more
失败:构建失败,并出现异常。
其中: 构建文件'E:\ GradleProj_workspace \ GadleDemoProj \ build.gradle'行:104
出了什么问题: 任务':cucumber'的执行失败。
以非零退出值1完成的处理'命令'C:\ Program Files \ Java \ jdk1.8.0_202 \ bin \ java.exe''
尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行,以获取更多日志输出。使用--scan运行以获取完整的见解。
在此版本中使用了不推荐使用的Gradle功能,使其与Gradle 7.0不兼容。 使用“ --warning-mode all”来显示各个弃用警告。 参见https://docs.gradle.org/6.5.1/userguide/command_line_interface.html#sec:command_line_warnings
1秒内失败 6个可执行的任务:1个已执行,5个最新
E:\ GradleProj_workspace \ GadleDemoProj>
-------------------------------------------- -------------------------------------------------- -----------------
我不确定在上述“ b” gradle任务中哪里出了问题。请尽早为我提供帮助,因为iam在这里浪费大量时间尝试多种可能性。我也想让您知道我是新的gradle东西。
还复制了我的黄瓜运行文件中存在的黄瓜选项
@CucumberOptions(features = { "classpath:featurefile" }, glue = { "classpath:com.inspire.brands.test.stepdefinition",
"classpath:com.inspire.brands.helper" },
plugin = { "pretty", "json:target/InspireBrands.json", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:" },
monochrome = true, tags = "@Api")
答案 0 :(得分:0)
请脱下json:要摆脱异常,您将发现无效方案!
答案 1 :(得分:0)
完整解决方案如下。
任务黄瓜(){ 取决于组装,测试类 doLast { javaexec { main =“ io.cucumber.core.cli.Main” classpath = configuration.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty',
'--plugin', 'json:target/InspireBrands.json',
'--plugin', 'com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:Report',
'--glue','com.inspire.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '@Api'
]
}
}
}
答案 2 :(得分:0)
我完整的build.gradle内容在下面给出
/*
插件{ id'java' id'maven-发布' id'java-library' id'java-gradle-plugin' }
存储库{
mavenCentral()
jcenter()
}
任务deleteGraphicsAssets(类型:删除){ 删除“构建” }
属性props =新的Properties()
props.load(new FileInputStream("$project.rootDir/src/main/resources/configFile/config.properties"))
props.each { prop ->
project.ext.set(prop.key, prop.value)
}
println“ $ ProductServicesAPI_QA_URL” println project.ProductServicesAPI_QA_URL println project.rootDir
依赖项{ //此依赖项导出到使用者,即在其编译类路径中找到。 api'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.2-jre'
implementation gradleApi()
testImplementation 'io.cucumber:cucumber-java:4.8.0'
compile group: 'io.cucumber', name: 'cucumber-jvm', version: '4.8.0'
compile group: 'io.cucumber', name: 'cucumber-core', version: '4.8.0'
compile group: 'io.cucumber', name: 'cucumber-testng', version: '4.8.0'
implementation 'io.cucumber:cucumber-picocontainer:4.7.4'
//实现'com.aventstack:extentreports:4.1.7' //实施'com.aventstack:extentreports-cucumber4-adapter:1.0.9'
testCompile group: 'com.aventstack', name: 'extentreports', version: '4.1.7'
testCompile group: 'com.aventstack', name: 'extentreports-cucumber4-adapter', version: '1.2.0'
implementation 'io.cucumber:cucumber-gherkin:5.1.0'
testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
implementation 'io.rest-assured:rest-assured:3.3.0'
implementation 'org.json:json:20180813'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'org.apache.poi:poi-ooxml:4.1.2'
compile group: 'org.seleniumhq.selenium', name: 'selenium-server', version: '3.141.59'
implementation 'com.paulhammant:ngwebdriver:1.1.4'
compile group: 'org.seleniumhq.selenium', name: 'selenium-htmlunit-driver', version: '2.52.0'
implementation 'org.seleniumhq.selenium:selenium-java:4.0.0-alpha-4'
//testImplementation 'org.hamcrest:hamcrest-all:2.2'
}
tasks.withType(JavaCompile) {
options.compilerArgs += ['-Xdoclint:none', '-Xlint:none', '-nowarn']
options.encoding = 'UTF-8'
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
任务黄瓜(){ 取决于组装,测试类 doLast { javaexec { main =“ io.cucumber.core.cli.Main” classpath = configuration.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty',
'--plugin', 'json:target/InspireBrands.json',
'--plugin', 'com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:Report',
'--glue','com.inspire.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '@Api'
]
}
}
}
/ *
任务Cucumber(){
取决于组装,测试类
doLast {
javaexec {
main =“ io.cucumber.core.cli.Main”
classpath = configuration.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', 'json:target/InspireBrands.json', 'com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:',
'--monochrome', 'true',
'--features','src\test\resources\featurefile',
'--glue','com.inspire.brands.test.stepdefinition',
'src/test/resources','src/main/java',
'--tags', '@Api'
]
}
}
}
* /
/ * task.test { 通过黄瓜定稿 } * /