在@CucumberOptions中创建自定义文件报告名称 [英] Create customize file report name in @CucumberOptions

查看:432
本文介绍了在@CucumberOptions中创建自定义文件报告名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义范围报告,这是添加到我的黄瓜框架中的第三方报告工具,我想将report.html的名称自定义为 Outputfilename .html无法执行此操作,因为 Outputfilename的值来自我的配置文件。

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();

非常感谢您的帮助。

推荐答案

最后我修复了它-

因此,基本上,我们需要更改运行程序类,例如

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");
    }

这篇关于在@CucumberOptions中创建自定义文件报告名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆