0

Facing a issue similar to this when trying to get unique method names using ITest. I have a factory method with a data provider defined to test the same test case with multiple data. When I try to generate unique method names for each test run appending the parameters responsible for each test run using ITest and getTestName(). I can observe my TEST-TESTSUIT.xml file generates the unique method names correctly as below.

"1.1.1.1_testmethod_parameter1" time="0.252"
"1.1.1.1_testmethod_parameter2" time="0.252"

But in Index.html file I can observe a repetitive value which is responsible for last test run has appended for all the tests as below. In the index.html file I can see a value as (1.1.1.20_login_parameter1) getting repeated for all the test results.

1.1.1.1_testmethod_parameter1 Test class: xxxxxxxx(1.1.1.20_login_parameter1) Test method: 1.1.1.1

1.1.1.1_testmethod_parameter1 Test class: xxxxxxxx(1.1.1.20_login_parameter1) Test method: 1.1.1.1

What could be the reason for this. Is this a bug in the testng side. Can we fix this from our side. I tried various approaches suggested in [1]. But anything didn't worked for me. Appreciate your ideas on this behavior

Sample source code similar to what I tried is as below

import org.testng.ITest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import java.lang.reflect.Method;

public class TestAPIDD implements ITest
{
private String apiName;

String testInstanceName = "";
Parameters tp;

@Factory(dataProvider="apiDataProvider")
public TestAPIDD(String apiName, String userName) {

    tp = new Parameters(apiName, userName);
    this.apiName = tp.getAPIName();
}

@DataProvider(name = "apiDataProvider")
public Object[][] dataProvider() {
    return new Object[][] { { "multiResourceAPI", "publisher1" }, { "ma     lformedAPI", "publisher2" }, { "wsdlAPI","admin" } };
}

/**
 * Constructor for the class TestAPIDD
 */
public TestAPIDD() {

}

/**
 * Login Test
 */
@Test(description="1.1.1.1")
public void testLogin()
{
   System.out.println("USER NAME: "+ tp.getUserName());
   Assert.assertTrue(true);

}

@Test(description="1.1.1.2")
public void testAPICreate() 
{
    System.out.println("APINAME: "+ tp.getAPIName());
    this.helperMethod();
    Assert.assertTrue(true);
}

@BeforeMethod(alwaysRun = true)
public void changeTestCaseName(Method method) {
    testInstanceName = method.getAnnotation(Test.class).description() + "_" + method.getName() +"_"+ apiName;
}

private void helperMethod() {
    System.out.println("TEST HELPER");
}

/**
 * Implementation of the getTestName in org.testng.ITest Interface.
 * This will set the name for the test case in TEST-TestSuite.xml
 */
public String getTestName() {
    return testInstanceName;
}

}

Appreciate your helps on how to fix this issue. Is this a bug in Testng side

1 Answers1

0

Was able to get this issue fixed by writing a CustomTestHTMLReporter.java class by removing the testname value that gets appended at the end of the class name in the index.html and adding the newly created CustomTestHTMLReporter class as a Listener in the testng.xml file.

Guide used - section 11 Custom Report in [1]

[1]. https://examples.javacodegeeks.com/enterprise-java/testng/testng-html-xml-reports-example/