Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the default listeners in TestNG, and where do I find this list?

I was curious to know what the default listeners are in TestNG. I saw a bool property on the Ant task for useDefaultListeners but I would like to know what these are and where I can find them.

like image 817
Mohamed Nuur Avatar asked Mar 04 '10 22:03

Mohamed Nuur


People also ask

What are the listeners in TestNG?

Listeners are TestNG annotations that literally “listen” to the events in a script and modify TestNG behaviour accordingly. These listeners are applied as interfaces in the code.

What are the listeners in selenium?

Listeners are basically the ones who have the ability to listen to a particular event. It is defined as an interface that modifies the behavior of the system. Listeners allow customization of reports and logs. To get a better idea about how listeners work in Selenium, we need to understand its major types.

What is the difference between WebDriver listener and TestNG listeners?

WebDriver works on different automation events whereas TestNG works on different test's related events. The point to note is that, with WebDriver listeners, "Logging" happens before/after event occurance such as click/SendKeys etc.

Is TestNG listeners are used to create logs?

Above Interface are called TestNG Listeners. These interfaces are used in selenium to generate logs or customize the TestNG reports. In this tutorial, we will implement the ITestListener. OnStart- OnStart method is called when any Test starts.


2 Answers

There are four default reporters:

http://code.google.com/p/testng/source/browse/trunk/src/org/testng/reporters/SuiteHTMLReporter.java

The main reporter that creates the HTML reports.

http://code.google.com/p/testng/source/browse/trunk/src/org/testng/reporters/FailedReporter.java

This reporter creates testng-failed.xml

http://code.google.com/p/testng/source/browse/trunk/src/org/testng/reporters/XMLReporter.java

This reporter generates an XML file that captures the entire description of this test run. This XML file is used by other tools for further generation (PDF, etc...).

http://code.google.com/p/testng/source/browse/trunk/src/org/testng/reporters/EmailableReporter.java

This reporter creates a file that is suitable to be emailed either attached or inline.

Hope this helps.

--
Cedric

like image 140
Cedric Beust Avatar answered Oct 24 '22 19:10

Cedric Beust


These seem to change every so often. The answer seems to be to look in the source code - initializeDefaultListeners()

private void initializeDefaultListeners() {
  m_testListeners.add(new ExitCodeListener(this));
  if (m_useDefaultListeners) {
    addReporter(SuiteHTMLReporter.class);
    addReporter(FailedReporter.class);
    addReporter(XMLReporter.class);
    addReporter(EmailableReporter.class);
    addReporter(JUnitReportReporter.class);
  }
}

When I experimented with altering this (to remove SuiteHTMLReporter), it was important to retain the difference between listeners and reporters, and to retain the order of the reporters.

like image 23
JodaStephen Avatar answered Oct 24 '22 21:10

JodaStephen