How to save Allure Environment data automatically

Roman Sheremeta
2 min readDec 30, 2020

--

This guide explains how to serve and save Allure Environment data in an easily manner.

So, firstly, you need to add this Library to your project. Since it’s not pushed to the MVN central repository yet, there are two installation options:

  • Download already compiled and packaged Allure-Environment-Creator-1.0.jar file HERE and proceed to the 2nd step
  • Download source code HERE to your local machine, make a jar by running mvn package in the repo directory and proceed to the 2nd step

2. Put a Allure-Environment-Creator-1.0.jar file into your project directory (for instance — create root dir ~/libs/ and paste there)

3. After that, add this dependency to your pom.xml (systemPath value is for instance)

<dependency>
<groupId>com.github.rsheremeta</groupId>
<artifactId>Allure-Environment-Creator</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/libs/Allure-Environment-Creator-1.0.jar</systemPath>
</dependency>

Now when we’re done with adding a Library to the project, just do this in your @AfterSuite method (or @AfterClass for JUnit):

import com.github.rsheremeta.AllureEnv;
public class BaseTest {
@AfterSuite(alwaysRun = true)
public void afterSuite() {
// Instantiate a map with your needed Environment values

Map<String, String> envData = new HashMap<>();
envData.put("Base URL", "https://google.com/");
envData.put("User", "Admin");
envData.put("OS", System.getProperty("os.name"));

/*
If your /allure-results is in /target – just pass instantiated map as a parameter
*/
AllureEnv.createAllureEnvironmentFile(envData);

/*
If your /allure-results is in custom directory – just pass one more parameter
with customPath to your /allure-results directory
*/
AllureEnv.createAllureEnvironmentFile(envData, "/custom/path/to/allure-results/");

// some your other code
}
}

Now you're all set to run your suite.

Once suite is finished, generate allure report and take a look on the Environment section:

Allure Report with filled Environment section

That’s pretty much it. Thanks for reading!

--

--