How to include screenshots in ReportNG report?

Any test automation report is incomplete without the screenshots and including them in ReportNG is not that much difficult. In today’s post we will see how we can include the screenshots in ReportNG report. If you are wondering how to configure ReportNg with selenium then you can refer my previous post.

Here I am again considering that you already have below set-up-

  • Your project is already set-up in Eclipse
  • Project already has testng.xml file.
  • ReportNG is already set-up with Selenium and TestNG.

If above conditions are true then you just need to complete two steps-

1: Make it Escape_Property=false like this-


2: Now take the screenshot after some actions and pass through Reporter.log method to ReportNG report-


Now run your testng.xml file and open the test report. If you have configured ReportNG properly and above set-up then you report should look like this-


How to configure ReportNG with Selenium WebDriver?

Selenium WebDriver is open source test automation framework which does not come with reporting facility. So selenium user has to be depended upon the third party plug-ins.

ReportNG is a simple HTML reporting plug-in for the TestNG unit-testing framework. It is intended as a replacement for the default TestNG HTML report. There are very few steps to configure ReportNG with WebDriver+TestNG.

To configure it we need three jar files (Guice, ReportNG, and Velocity-dep) which you can download from here-


Once you have these three jar files, please include them in your project-


Here I am considering that you already have TestNg.xml file inside your project; if Yes, please include below listeners inside suite tag-

<listener class-name=”org.uncommons.reportng.HTMLReporter”/>
<listener class-name=”org.uncommons.reportng.JUnitXMLReporter”/>

Once you done, your testng.xml file should look like this-


Now last step, disable the default testng listener by-

Right click on Project folder > click on Properties > click on TestNG which visible in left pane.


All set, now run your testng.xml file and refresh your project. Once all done, It will add ‘test-output’ folder. Go to test-output > html > and open index.html to see the report.


Your report should look like this after all above set-up-


How to configure Properties file with Selenium WebDriver?

Why Properties file?

To hide sensitive information of the projects we save the information in properties file.

To configure Properties file, create a new file and save as with .properties extension. Now add the data in following manner in Properties file:


Now use below lines of code to read this property file-

FileInputStream prop = new FileInputStream (“D:\\Selenium_Projects\\Property\\”);
Properties a = new Properties ();
try {
} catch (IOException e) {

String URL=a.getProperty(“URL”);
String USR=a.getProperty(“INT_USR”);
String PWD=a.getProperty(“INT_PWD”);
}catch (FileNotFoundException e){

How to configure Selenium Grid?

Here I noted down some quick steps to configure Selenium Grid on windows. I am assuming that you are aware about selenium and its features. So here we go-

  • Download Selenium Standalone Jar file from here.
  • Dump it somewhere in host and node machines.
  • Open CMD at Host machine and go to location where you have been dumped the jar file.
  • Now run this command Java –jar seleniumserver-standalone_version.jar –role hub.
  • Now open http://localhost:4444/grid/console.
  • Now go to Node machine.
  • Open CMD at Node machine and go to location where you have been dumped the jar file.
  • Run the below commend if machine is remote-

java –jar selenium-server-standalone_version – role webdriver –hubHost HOST MACHINE NAME – “browserName=iexplorer, platform=WINDOWS” –port 5556

  • Run the below commend if machine is same machine where host is running-

java –jar selenium-server-standalone_version – role webdriver – “browserName=iexplorer, platform=WINDOWS” hubHost http://localhost:4444/grid/register –port 5555

How to run Selenium + TestNG script from Command Line?

This is an alternate way to execute our selenium script from command prompt. Here, I am considering few points-

  • Your project is already set-up in Eclipse
  • Project already has testng.xml file.
  • All selenium and other third party jar files are located under project home folder (lib folder).
  • You are able to execute your script by running testng.xml file.


If above conditions are matching then very few steps are there to execute same script from command prompt. Follow the below steps-

Open Command Prompt and Go to Project home directory-


Set the class path and libraries path by running below command-

set classpath=<Project Home Path>\bin;<Project Home Path>\lib\*


Now run the testng.xml file by running below command-

java org.testng.TestNG testng.xml—-Make sure “org.testng.TestNG” TestNG word should have ‘T’ and ‘NG’ in caps.


I hope it would help people to run testng.xml file from the command prompt.

EventFiringWebDriver, WebDriverEventListener, and AbstarctWebDriverEventListener

Before getting into the sample code, lets have a look on EventFiringWebDriver, WebDriverEventListener, and AbstarctWebDriverEventListener descriptions.

  • EventFiringWebDriver is a class and wrapper around an arbitrary webdriver instance which supports registering of a WebDriverEventListener.
  • WebDriverEventListener is interface which includes list of abstract events methods and all should be implemented if we are implementing it.
  • AbstarctWebDriverEventListener is abstract class which has implemented WebDriverEventListener interface. We can extend this class if we are only interested in some events. All methods provided by this class have an empty method body.

So we can choose between EventFiringWebDriver and AbstarctWebDriverEventListener according to our needs.

Note: I have used AbstarctWebDriverEventListener class in below example.

Let’s have a look on example-

Create a class file and extends AbstarctWebDriverEventListener class-
public class WebDriverEventListenerClass extends AbstractWebDriverEventListener {
public void onException(Throwable arg0, WebDriver driver) {

File screenShot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(screenShot, new File(“c:\\tmp\\exception.png”));
} catch (IOException e) {

Create another class file and register WebDriverEventListenerClass file as it has implemented onException event method-

public class EventFiringDriverExample {
public void Events(){
System.setProperty(“”, “D:/Training/IE_Driver/IEDriverServer.exe”);

WebDriver driver = new InternetExplorerDriver();

// Creating EventFiringWebDriver instance

EventFiringWebDriver eventFiringDriver= new EventFiringWebDriver(driver);

// Creating instance of eventListener, that we just defined
eventFiringDriver.register(new WebDriverEventListenerClass());




Once you run ‘Events()’ method, it will open Google and search for element which is not available. In this case, method will throw WebElementNotFound exception and system will capture the screenshot and save it at “c:\\tmp\\exception.png” location..

How to generate logs with CodedUI?

Why logs? Well, it helps to debug the problem in our script. Usually logging and capturing the screenshots are not enable by default with CodedUI and to make it, we need to make some set up.

Follow the below steps to enable logging and capturing the screenshots-

1: Go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE location and search for ‘QTAgent32_40.exe.config’ and ‘QTAgent32.exe.config’. Make sure you have edit permission for these config files.

2: Modify the value for ‘EqtTraceLevel‘:


3: Add App.config file in your project and add the following code under the configuration node:


4: Add following code in CodedUITest1.cs file-


5: Now run the test.

6: Open Test Explorer and click on Output hyperlink-


7: Click on UITestActionLog.html link.


8: Now check your script logs-