java—如何使用基于gradle的项目生成附带失败屏幕截图和cucumber.json文件的cucumber html报告

lskq00tm  于 2021-07-12  发布在  Java
关注(0)|答案(2)|浏览(344)

使用gradle,我试图生成一个带有失败截图的cucumber html报告,由于安全原因,我不能在build.gradle文件中有在线插件,所以我必须下载所需的jar和插件,并在build.gradle文件中手动实现和配置库。
请建议如何在build.gradle中配置testrunner文件,并使用cucumber.json文件生成cucumber html报告
build.gradle文件

plugins {
    id 'java'
    id 'idea'
}

group 'org.example'
version '1.0-SNAPSHOT'

configurations {
    cucumberRuntime.extendsFrom testRuntime
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "io.cucumber.api.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'stepDef', 'src/test/java']
        }
    }
}

repositories {

    mavenCentral()
}
dependencies {
    implementation fileTree(dir:System.getProperty("user.dir")+'/Plugin',include:['*.jar'])
    implementation files('junit-4.12')
    implementation files('testng-6.7.jar')
    implementation files('junit-jupiter-api-5.6.2')
    implementation files('hamcrest-all-1.3')
    .....................

testrunner文件

package TestRunner;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/resources",
        glue = "StepDefs",
        plugin = {
                "pretty", "html:target/cucumber-html-report", "json:target/cucumber.json", "pretty:target/cucumber-pretty.txt"
        }
)

public class TestRunner {

}
kmynzznz

kmynzznz1#

无论什么 StepDefs 可能是。。。
跑步 gradle cucumber --info 可能对调试有用。。。因为错误信息 finished with non-zero exit value 1 只表示“错误”或“不成功”。
首先,您可能需要这些java依赖关系:

testImplementation 'io.cucumber:cucumber-java:6.5.0'
testImplementation 'io.cucumber:cucumber-junit:6.5.0'

可能还需要补充一点 gradle.cucumber 作为 --glue 进入争论 args ,如文件所示。任务相关性 compileTestJava 应该是 testClasses . html 通常是一个插件,它需要一个输出目录,因此应该如下所示:

task cucumber() {
    dependsOn assemble, testClasses
    doFirst {

    }
    doLast {
        javaexec {
            main = 'io.cucumber.core.cli.Main'
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = [
                '--plugin', 'pretty', 'html:target/reports',
                '--glue', 'gradle.cucumber',
                'src/test/resources'
            ]
        }
    }
}

这些 args 也可以用java注解;不知道哪个优先。
当定义两次参数时,这可能毫无意义,只会造成混乱。
确保遵循说明4:
添加功能 .feature 文件和关联的步骤Map类 .javasrc/test/resources 以及 src/test/java 分别在 gradle.cucumber 包裹。 -g , --glue 从中加载粘合代码(步骤定义、挂钩和插件)的路径。
使用junit运行时,还可以通过 junit-platform.properties 文件。
最简单的可能是从 cucumber-java-skeleton (已知正在工作)。

pw136qt2

pw136qt22#

它对我不起作用,如果我运行这个cumber任务,它会给我错误
任务:cucumber失败错误:无法找到或加载主类io.cucumber.api.cli.main
原因:java.lang.classnotfoundexception:io.cucumber.api.cli.main
错误:找不到或加载主类io.cucumber.api.cli.main
我已经创建了一个执行testrunner.java文件的任务cucumberrunner,它正在创建cucumber.json文件和html报告,但是htlm报告但是html报告不应该是奇怪的没有图形和无色的
我使用的build.gradle:

configurations {
cucumberRuntime {
extendsFrom testRuntime
}
}

task cucumber() {
dependsOn assemble, testClasses
doFirst {

}
doLast {
    javaexec {
        main = 'io.cucumber.api.cli.Main'     // tried with  io.cucumber.core.cli.Main
        classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
        args = [
                '--plugin', 'pretty', 'html:target/reports',
                '--glue', 'gradle.cucumber',
                'src/test/resources'
        ]
    }
}

}
task cucumberRunner(type: Test) {
include '**/**TestRunner.class'
}

Also I have added jars
implementation files('junit-4.12')
implementation files('testng-6.0.jar')
implementation files('cucumber-core-6.0.0')
implementation files('cucumber-java-6.0.0')
implementation files('cucumber-plugin-6.0.0')
implementation files('cucumber-junit-6.0.0')
implementation files('cucumber-testng-6.0.0')
implementation files('cucumber-jvm-deps-1.0.5')
implementation files('cucumber-gherkin-6.0.0')
implementation files('cucumber-java8-6.0.0')
implementation files('cucumber-html-0.2.3')
```

相关问题