前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Java Allure 报告中增加Environment属性信息

Java Allure 报告中增加Environment属性信息

作者头像
孟船长
发布2023-01-14 11:17:29
7170
发布2023-01-14 11:17:29
举报

通过allureEnvironmentWriter即可给allure报告增加environment显示信息。此段代码会默认在target/allure-results文件夹生成一个environment.xml文件,但是想要在报告中显示,还需要将这个environment.xml复制到外层的allure-results文件夹中。

“所以如果你的environment显示信息是固定的,你可以直接在allure-results文件夹中建一个environment.xml文件,内容填写你想要在报告中展示的环境信息。”

代码如下:

代码语言:javascript
复制
package com.demo.testng;

import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.testng.annotations.*;


import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;


import org.apache.commons.io.FileUtils;
import static com.github.automatedowl.tools.AllureEnvironmentWriter.allureEnvironmentWriter;


public class TestNGDemo1 {

    @BeforeSuite
    void setAllureEnvironment() throws IOException {
        allureEnvironmentWriter(
                ImmutableMap.<String, String>builder()
                        .put("Browser", "Chrome")
                        .put("Author", "孟船长")
                        .put("公众号", "自动化测试实战")
                        .build());


        File envTarget = new File("allure-results/environment.xml");
        File envSrc = new File("target/allure-results/environment.xml");
        FileUtils.copyFile(envSrc, envTarget);
    }


    @BeforeClass
    public void openBrowser(){
        System.out.println("Open browser of @BeforeMethod");
    }


    @AfterClass
    public void closeBrowser(){
        System.out.println("Close browser of @AfterMehtod");
    }


    @Test(groups = {"groups01"})
    public void test01(){
        System.out.println("This is test01");
    }


    @Test(groups = {"groups01", "groups02"})
    public void test02(){
        System.out.println("This is test02");
    }
}

依赖

代码语言:javascript
复制
<dependency>
	<groupId>com.github.automatedowl</groupId>
	<artifactId>allure-environment-writer</artifactId>
	<version>1.0.0</version>
</dependency>

在终端Terminal中先执行用例mvn clean test

再查看报告allure serve allure-results

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2022-12-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 自动化测试实战 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档