As we know, TestNG provides default html reports with basic information like No. of tests passed, failed, skipped and time taken to execute these tests in milliseconds. But you may not find it very helpful as the reports generated by TestNG has very little information.
IMethodInterceptor is used to alter/modify the list of test methods to be executed by TestNG.
When we implement
IMethodInterceptor interface which has just one method to implement
'intercept(java.util.List, using this method we can reorder the list of test methods and return List of IMethodInstance which TestNG runs. TestNG will now run these test methods in the same order which is found in the returned list.
In previous tutorial we have seen executing testng.xml tests from command line. Now here we will look into executing testng.xml using batch file (.bat) file. A batch file (.bat) is used in DOS and Windows, which is an unformatted text file that consists of a series of commands to be executed by the command line interpreter.
Let us jump into simple example by taking two classes each has three or more @Test methods.
We can execute testng.xml file in different ways.
3. Ant / Maven
4. Command Line
5. Batch File.
Please visit for the updated article customized emailable report along with screenshots which works perfect for newer versions of testNG and tested with testng latest version 6.14.3
This example was using older testng version.
When ever we execute tests with TestNG, it will generate a default html report with basic information.
As we know, we can pass parameter values to the test methods during run time from testng xml file by specifying Parameters annotation to test method.
To do this, we need to declare parameters tag in xml file using 'name' and 'value' attribute.Where the name attribute of the tag defines name of the parameter and the value attribute defines the value of the parameter.
In this example we will see how to pass the data to Dataproviders by reading the data from excel sheet. DataProvider helps to send multiple sets of data to a test method. But here we need to make sure that the array returned by the dataprovider should match with the test method parameters.
We will write a simple program in which we will validate login screen by taking multiple usernames and passwords. The annotated method must return object where each object can be assigned to the test method one as username and the other parameter as password.
In this tutorial, we will see taking a screen shot with test name and placing it in a folder by creating a folder with Test Class Name.
As we are taking screen shots on failure, we need to add logic in creating a screen shot and naming it with test name and place it in its test class name respectively.
We can get the test class name using 'result.getInstanceName()'. Test class name looks some thing like "com.pack.sample.HomePage". But we need to create a folder name with test class name i.e 'HomePage'.
We have seen an example to Re-run failed tests using iRetryListener. In the previous example, the count of the tests run was changing based on the maxRetryCountvalue. To over come that, we need to add the below code snippet for onFinish method by implementing 'ITestListener'