How to Set Environment in Allure Report

Profile picture for user arilio666

In this article, we will see how we can set environment details in the allure report using java. There is a java library that will allow us to write in key/value pair to environment.xml file on runtime using allure results directly.

The said library supports both JUnit and TestNG as of now.

<dependency>
    <groupId>com.github.automatedowl</groupId>
    <artifactId>allure-environment-writer</artifactId>
    <version>1.0.0</version>
</dependency>

Add this dependency to your pom.xml.

  • This library will help us quickly write the key/value set to environment.xml to the allure-results directory at any test stage.
  • This can also configure the path of the 'allure-results' directory.
  • The immutableMap object is used here to create a set of immutable values for the specific environment.

Example:

  • In this article, we will use JUnit and work this out.
    @Before
    public void setAllureEnvironment() {
        allureEnvironmentWriter(
                ImmutableMap.<String, String>builder().put("Browser", "Chrome").put("Browser.Version", "70.0.3538.77")
                        .put("URL", "http://programsbuzz.com").build(),
                System.getProperty("user.dir") + "/allure-results/");
    }
  • Add this onto your @before, and this will get executed before the test execution.
  • In case of any error due to the ImmutableMap part, add this dependency.
<dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>23.0</version>
</dependency>
  • Add in your environment details here, and then when we generate the report, it should look like this.
  • There we go. Our personalized environment has been written using the setAllureEnvironment library successfully.