Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99413

testng - Get name of the class that contains failed test

$
0
0
<test name="Test">
   <classes>
     <class name="io.test.FirstTest"/>
   </classes>
</test>

I want to get name of the FirsTest class without the package name inside onTestFailure. In other wors, I need to get FirstTest, not io.test.FirstTest. How to do so?

   public class TestListener extends TestListenerAdapter {

    @Override
    public void onTestFailure(ITestResult testResult) {

    }
  }

I have used testResult.getInstanceName(), but it returns io.test.FirstTest. Hence, I have used string.substring():

   final String name = testResult.getInstanceName();
   final String result = name.substring(navn.lastIndexOf(".") + 1).trim();

But is there a better solution?


Viewing all articles
Browse latest Browse all 99413

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>