How to append TestNg method name with axes of Jenkins Matrix Pipeline with Allure Report?

Viewed 63

I am using the following combination of tools in our automation suite.

  1. Java 17
  2. TestNG
  3. Allure Reports
  4. Jenkins Pipeline Matrix Project

I am able to successfully, combine the allure reports across the axes in Jenkins (https://stackoverflow.com/a/73063270/2280218). But the same tests executed across different axes are combined in the UI into a single item, others being listed as retries.

One of the solutions, we came up with to solve this issue is to append the axes value to the test method name. This makes the tests unique both getting listed on the allure results tab. But we are not able to make this work.

public class TestNameModifier implements ITestListener {
    @Override
    public void onTestStart(ITestResult result) {
        try {
            BaseTestMethod baseTestMethod = (BaseTestMethod) result.getMethod();
            Field f = baseTestMethod.getClass().getSuperclass().getDeclaredField("m_methodName");
            f.setAccessible(true);
            f.set(baseTestMethod, baseTestMethod.getMethodName() + " [" + System.getenv("CITY_NAME") + "]");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Please help to get this working. Thanks.

0 Answers
Related