java - How to get the name of the class that is acted upon by listener of TestNG? -


hello have simple testng project has sampletest.java class file has 2 test cases , have added listener called mylistener . have mylistener.java class file extends testlistener of testng in i'm printing pass or fail or skipped depending upon test case execution. every time run sampletest can see pass/fail in console.. want classname

my problem statement is, how can test case file name (i.e. sampletest here) in mylistener class??? tried stacktrace no help.. guess not being called acting upon/listening testcases in file.. please let me know how can name of class in listener????

sampletest.java:

package com.abc;  import org.testng.annotations.listeners; import org.testng.annotations.test; @listeners({ com.mindtree.mylistener.class}) public class sampletest {      @test     public void sampletest() throws exception{         system.out.println("hello world");     }     @test     public void sampletest1() throws exception{         system.out.println("hello swarna");     } } 

mylistener.java:

package com.abc;  import org.testng.itestresult; import org.testng.testlisteneradapter;  public class mylistener extends testlisteneradapter  {      private int m_count = 0;        @override       public void ontestfailure(itestresult tr) {         log("fail");       }        @override       public void ontestskipped(itestresult tr) {         log("skipped");       }        @override       public void ontestsuccess(itestresult tr) {         log("\nsuccess\n");       ## want print here testcase class name       }        private void log(string string) {         system.out.print(string);         if (++m_count % 40 == 0) {           system.out.println("");         }       }  } 

but wont work multiple testcase files.. create object of sampletest in mylistener access classname through getters , setters

you can find out examining stacktrace like:

stacktraceelement trace[] = thread.currentthread().getstacktrace(); can the calling class trace[i].getclassname().

note pretty expensive, don't use in loggers etc.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -