我正在这样做:-
cucumberOption.properties
#cucumber.options=--plugin html:output/cucumber-html-report
#src/test/resources
cucumber.options.feature =src/test/resources
cucumber.options.report.html=--plugin html:output/cucumber-html-report
Java 类:CreateCucumberOptions.java
加载属性文件的方法:-
private static void loadPropertiesFile(){
InputStream input = null;
try{
String filename = "cucumberOptions.properties";
input = CreateCucumberOptions.class.getClassLoader().getResourceAsStream(filename);
if(input==null){
LOGGER.error("Sorry, unable to find " + filename);
return;
}
prop.load(input);
}catch(IOException e){
e.printStackTrace();
}finally{
if(input!=null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
获取和设置 CucumberOptions 的方法
private String createAndGetCucumberOption(){
StringBuilder sb = new StringBuilder();
String featureFilesPath =
prop.getProperty("cucumber.options.feature");
LOGGER.info(" featureFilesPath: " +featureFilesPath);
String htmlOutputReport =
prop.getProperty("cucumber.options.report.html");
LOGGER.info(" htmlOutputReport: " +htmlOutputReport);
sb.append(htmlOutputReport);
sb.append(" ");
sb.append(featureFilesPath);
return sb.toString();
}
private void setOptions(){
String value = createAndGetCucumberOption();
LOGGER.info(" Value: " +value);
System.setProperty(KEY, value);
}
运行它的主要方法:-
public static void main(String[] args) {
CreateCucumberOptions cucumberOptions = new CreateCucumberOptions();
JUnitCore junitRunner = new JUnitCore();
loadPropertiesFile();
cucumberOptions.setOptions();
junitRunner.run(cucumberTest.runners.RunGwMLCompareTests.class);
}
RunGwMLCompareTests.class 是我的 Cucumber 类
@
RunWith(Cucumber.class)
@CucumberOptions(
monochrome = true,
tags = {"@passed"},
glue = "cucumberTest.steps")
public class RunGwMLCompareTests {
public RunGwMLCompareTests(){
}
}
因此,基本上现在您可以通过属性文件和其他选项(如胶水定义 java 类)来设置输出报告和功能文件夹。要运行测试用例,只需运行您的主类。
问候,
维克拉姆·帕塔尼亚