我需要通过gradle调用Cucumber Runner,然后依次执行所有测试执行和报告 [英] I need to invoke Cucumber Runner through gradle and which in turn does all the test execution and reporting also
问题描述
我不确定我们是否可以运行黄瓜赛跑者类,该类又可以运行所有测试,甚至还可以执行报告部分。
I am not sure whether we can run the cucumber runner class which in turn runs all the tests and does even the reporting part also.
就像在Cucumber Maven项目中一样,我们可以运行黄瓜运行程序文件可以在相同的上下文中运行以执行测试甚至生成报告,是否可以通过调用Cucumber运行程序类在gradle中实现。
Just like in Cucumber Maven project we run the Cucumber runner file to execute the tests and even generates the reports after run in the same context is it doable in gradle by calling the Cucumber runner class.
我的黄瓜运行程序如下
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
}
}
这里我基本上是在初始化我的黄瓜功能和类定义。 / p>
Here I am basically initializing my cucumber feature and class definition.
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', version: '3.14.0'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.14.0'
compile group: 'org.seleniumhq.selenium', name: 'selenium-server', version: '3.14.0'
//compile group: 'org.seleniumhq.selenium', name: 'selenium-server', version: '2.53.1'
}
test {
reports {
junitXml.enabled = true
html.enabled = false
}
testLogging {
events 'passed', 'failed', 'standardError'
showStandardStreams = true
}
}
此处运行此-您需要使用命令
Here to run this- you need to use the command
渐变构建或测试
gradle build or test
命令需要运行在终端。
让我知道是否有帮助。
command needs to be run in terminal. Let me know if this helps.
这篇关于我需要通过gradle调用Cucumber Runner,然后依次执行所有测试执行和报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!