通過allureEnvironmentWriter 即可給allure 報告增加environment顯示信息,。此段代碼會默認在target/allure-results 文件夾生成一個environment.xml 文件,,但是想要在報告中顯示,還需要將這個environment.xml 復制到外層的allure-results 文件夾中,。 “所以如果你的environment 顯示信息是固定的,,你可以直接在allure-results 文件夾中建一個environment.xml 文件,內(nèi)容填寫你想要在報告中展示的環(huán)境信息,。 ” 代碼如下: 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("公眾號", "自動化測試實戰(zhàn)") .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"); } }
依賴 <dependency> <groupId>com.github.automatedowl</groupId> <artifactId>allure-environment-writer</artifactId> <version>1.0.0</version> </dependency>
在終端Terminal中先執(zhí)行用例mvn clean test 再查看報告allure serve allure-results
|