我需要通过gradle调用Cucumber Runner,然后依次执行所有测试执行和报告

问题描述

我不确定我们是否可以运行“黄瓜赛跑者”类,该类又可以运行所有测试,甚至还可以执行报告部分。

就像在Cucumber Maven项目中一样,我们运行CucumberRunner文件来执行测试,甚至在相同的上下文中运行后生成报告,是否可以通过调用CucumberRunner类在gradle中实现。

我的黄瓜赛跑者如下

    import org.testng.annotations.AfterClass;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;


     @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")
    
    
    public class **InspireBrandsTestRunner** extends AbstractTestNGCucumberTests {
    
        
        @AfterClass(alwaysRun = true)
        public static void writeExtentReport() {
                
            ReporterUtil.archiveReport();
            
        }
        
    }
    

解决方法

    package runners;
    
    import com.cucumber.listener.ExtentProperties;
    import com.cucumber.listener.Reporter;
    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;
    import org.junit.BeforeClass;
    import org.junit.runner.RunWith;
    import stepDefinations.Hooks;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(
            features = ".//test//java//FeatureList",glue = "stepDefinations",plugin = { "com.cucumber.listener.ExtentCucumberFormatter:","junit:target/cucumber-results.xml"},tags="@Smoke-Login",monochrome = true
    )
    public class TestRunner {
    
        @BeforeClass
        public static void setup(){
            //Initializing extent reporting here
}
}

在这里,我基本上是在初始化我的黄瓜功能和类定义。

plugins {
    id 'java'
}

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

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

repositories {
    mavenCentral()
}
dependencies {
    //junit
    testCompile 'junit:junit:4.12'
    compile group: 'org.testng',name: 'testng',version: '6.10'
    //cucumber
    compileOnly 'info.cukes:cucumber-jvm-deps:1.0.5'
    compile group: 'info.cukes',name: 'gherkin',version: '2.12.2'
    compile group: 'net.masterthought',name: 'cucumber-reporting',version: '3.18.0'
    testCompile group: 'info.cukes',name: 'cucumber-junit',version: '1.2.5'
    testCompile group: 'info.cukes',name: 'cucumber-picocontainer',version: '1.2.4'
    compile group: 'info.cukes',name: 'cucumber-java',version: '1.2.4'
    //reporting
    compile 'com.vimalselvam:cucumber-extentsreport:3.0.2'
    compile 'com.aventstack:extentreports:3.1.2'
    compile 'com.aventstack:extentreports:3.1.2'
    //logger
    compile group: 'log4j',name: 'log4j',version: '1.2.17'
    //selenium
    compile group: 'org.seleniumhq.selenium',name: 'selenium-chrome-driver',version: '3.14.0'
    compile group: 'org.seleniumhq.selenium',name: 'selenium-remote-driver',name: 'selenium-java',name: 'selenium-server',version: '3.14.0'
    //compile group: 'org.seleniumhq.selenium',version: '2.53.1'

}

test {
    reports {
        junitXml.enabled = true
        html.enabled = false
    }
    testLogging {
        events 'passed','failed','standardError'
        showStandardStreams = true
    }
}

在此运行-您需要使用命令

逐步构建或测试

命令需要在终端中运行。 让我知道是否有帮助。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...