I am using Data Provider in and report is displaying the same method name in all the tests in TestNG report.
static String TC_Name;
@DataProvider(name="SampleTestData")
public Object[][] testData() {
return new Object[][]{
{"TestCase1","Description1",""},
{"TestCase2","Description2",""},
{"TestCase3","Description3",""},
//{"TestCaseID_2","TC_Description","Negative",""},
};
}
@Test(dataProvider="SampleTestData", alwaysRun = true,testName="SampleTest")
public void testCaseInitialization(String testcaseID,String testcaseName, String Temp) {
Log.startTestCase(testcaseID + "_" + testcaseName);
TC_Name= testcaseID;
}
Now the output i want I want is "TestCase(1-3)". But i am getting "testCaseInitialization" in report.
I have tried the below way of hacking the report.:
@AfterMethod(alwaysRun = true)
public void setResultTestName(ITestResult result) {
try {
BaseTestMethod baseTestMethod = (BaseTestMethod) result.getMethod();
Field f = baseTestMethod.getClass().getSuperclass().getDeclaredField("m_methodName");
f.setAccessible(true);
f.set(baseTestMethod, TC_Name);
} catch (Exception e) {
// ErrorMessageHelper.getInstance().setErrorMessage(e);
Reporter.log("Exception : " + e.getMessage());
}
}
But this is giving me the "TestCase3" in all method names.
Can please anybody suggest , how else can I hack the report.
You can customize method name with @Test
annotation method only, if you want to retrieve "TestCase(1-3)" then apply it to Test Method. Report invoke method name of @Test
method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.