范围报告 4 - Java

尝试生成一个范围报告,这将使我能够运行一套测试类并将输出作为一个报告给出。


我当前的代码运行在 fin 中,它将运行我的 testNG.xml 文件并成功运行我的套件中的所有测试类。然而,范围报告本身似乎只保存最后运行的测试用例。我一生都无法弄清楚如何阻止它覆盖,而是附加到它。旧版本的范围报告使用 htmlreporter.setAppendExisting(true); 但这在范围 4 中不存在..


public class ExtentManager {

    ExtentHtmlReporter htmlReporter;

    ExtentReports extent;

    ExtentTest parentTest;

    ExtentTest childTest;

    DriverManager driverManager;

    WebDriver driver;

    Screenshot screenshot;

    Properties config;

    String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());


    /** Suite test as it will run, with Before/After instructions*/

    @BeforeTest

    public void beforeTest() throws IOException {

        /**Create extent reports and configure html report*/

        htmlReporter = new ExtentHtmlReporter(".//reports/ExtentReport"+timeStamp+".html");

        extent = new ExtentReports();

        extent.attachReporter(htmlReporter);

        htmlReporter.config().setTheme(Theme.DARK);

        htmlReporter.config().setDocumentTitle("Automation Testing");

        htmlReporter.config().setReportName("My Report");

        htmlReporter.config().setAutoCreateRelativePathMedia(true);

        htmlReporter.config().setTimeStampFormat("HH:mm:ss");

        screenshot = new Screenshot();

        config = new Properties();

        FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "/src/main/resources/Config.properties");

        config.load(fis);

    }


    public ExtentReports getExtent(){

        if(extent != null){

            return this.extent;

        } else {

            return new ExtentReports();

        }

    }


    @BeforeClass

    public void beforeClass() {

        /**Setup parent test, all child tests to follow

         *will attach to it for html report*/

        extent = getExtent();

        parentTest = extent.createTest(getClass().getSimpleName());

        driverManager = new DriverManager();

        driver = driverManager.getWebDriver();

        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

    }

慕斯709654
浏览 56回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java