Removing Parameters in Allure Reports

Parameters passed as arguments on testNG test method

So I’ve been working on this project and I needed to data drive my tests but firstly, I didn’t want my data to be polluting my report and secondly I didn’t want those data to be shown in the report. I did try looking in the internet on how to hide or remove these details on the report but couldn’t find any or an “allure-way” of doing it.

Luckily, allure creates a folder named “allure-result” in your project root directory and all the data shown in the report are stored here as a json file.

Generated json files

What we are interested in are those json files with “result” in their file name because the parameters are saved in there.

Parameters are stored as an array of json objects.

By now you might be laughing because you already know what we will do next. Yes, it’s funny but it works as a solution to my problem. 😂 😂 😂

So all we need to do is, at the end of test execution.

And 💥 that’s it.

Here is the code to remove the parameters on Allure report.

public class AllureUtilities {

public static void removeParametersInReport() throws Exception {
File dir = new File(System.getProperty("user.dir") + "/allure-results");
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
if (child.getName().contains("result")) {
removeParameterInJson(child);
}
}
} else {
throw new Exception(String.format("Directory %s/allure-results does not exist", System.getProperty("user.dir")));
}
}

private static void removeParameterInJson(File fileToBeUpdated) throws Exception {
try {
FileReader reader = new FileReader(fileToBeUpdated);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
List<Object> newParametersValues = new LinkedList<>();
jsonObject.put("parameters", newParametersValues);

try (FileWriter file = new FileWriter(fileToBeUpdated)) {
file.write(jsonObject.toString());
}

} catch (NullPointerException | ParseException | IOException e) {
throw new Exception(String.format("Something went wrong when updating %s", fileToBeUpdated.getName()), e);
}
}
}

Here is my sample test

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class sampleTest {
@Test(dataProvider = "sampleDataProvider")
public void sampleTest(String parameter1, String parameter2, String Parameter3, String parameter4,
String parameter5, String Parameter6, String parameter7, String parameter8, String Parameter9,
String parameter10) {
Assert.fail();
}

@DataProvider(name = "sampleDataProvider")
public Object[][] data() {
String[][] data = {{"name1", "password1", "email1", "address1", "other param1", "sex1", "birthday1", "others1", "others1", "other1"},
{"name2", "password2", "email2", "address2", "other param2", "sex2", "birthday2", "others2", "others2", "other2"},
{"name3", "password3", "email3", "address3", "other param3", "sex3", "birthday3", "others3", "others3", "other3"},
{"name4", "password4", "email4", "address5", "other param5", "sex5", "birthday5", "others5", "others5", "other5"}};
return data;
}

@AfterClass
public void tearDown() throws Exception {
AllureUtilities.removeParametersInReport();
}

}

Below is the generated report. See that parameters are no longer displayed compared to the first image above.

A funny solution but it works, if you have thousands of tests this will just add a few minutes at the end of execution. For this sample test, it only took 123ms to clean the report.

“Good Automation Brings Agility”. Software QA With An Agile Mindset. https://www.linkedin.com/in/rmalked/