Create customize file report name in @CucumberOptions

北城余情 提交于 2019-12-11 18:50:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!