问题
I am trying to customize the extent report which is a third party reporting tool added to my cucumber framework where I want to customize the name of the report.html to "Outputfilename".html which I unable to do as the value of "Outputfilename " is coming from my config file.
here is my testrunner code
@RunWith(Cucumber.class)
@CucumberOptions(
features = ".//src//test//java//FeatureList",glue = "stepDefinations",
plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/"+Outputfilename+".html",
"junit:target/cucumber-results.xml"},
tags="@smoke",
monochrome = true
)
public class TestRunner {
private static final String Outputfilename = FileReader.getInstance().getConfigReader().getReportPath();
I would really appreciate your help.
回答1:
Finally I fixed it-
So basically we need to change the runner class something like this-
package runners;
import PageObjectRep.CF;
import com.cucumber.listener.ExtentProperties;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import managers.FileReader;
import org.apache.log4j.PropertyConfigurator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import java.io.File;
@RunWith(Cucumber.class)
@CucumberOptions(
features = ".//src//test//java//FeatureList",glue = "stepDefinations",
plugin = { "com.cucumber.listener.ExtentCucumberFormatter:",
"junit:target/cucumber-results.xml"},
tags="@test",
monochrome = true
)
public class TestRunner {
static String ReportName= CF.ReportName(); //function which creates file name as per the execution and saved in string.
@BeforeClass
public static void setup() {
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath("target/cucumber-reports/"+ReportName+".html"); //used same string name to create the file with the same name.
PropertyConfigurator.configure(".//src//log4j.properties");
}
来源:https://stackoverflow.com/questions/52867952/create-customize-file-report-name-in-cucumberoptions