Friday, December 1, 2017

How to get a current class name and methods that executed in the class file using TestNG listeners?

Answer:

Use ITestResultITestContext and IMethodInstance which can give you class name and method name which are using.
for (ITestResult testResult : testResultSet) {
    String methodName = testResult.getName() + "(";
    for (Object arg : testResult.getParameters()) {
        methodName += arg == null ? "" : arg.toString() + ", ";
    }

    uniqueMethodMap.add(testResult.getName());
    methodList.add(testResult.getParameters().length > 0 ?    methodName.substring(0, methodName.length() - 2) + ")" : methodName + ")");
}

No comments:

Post a Comment