TestNG Tutorials

TestNG - Gradle example

Gradle is an open-source build automation tool that is designed to be flexible enough to build almost any type of software. Gradle runs on the JVM and you must have a Java Development Kit (JDK) installed to use it. You can find more information on Gradle

You can install the Gradle build tool on Linux, macOS, or Windows.

Allure report example using testng and maven

Allure is an open-source framework designed to create interactive and comprehensive test report by Yandex QA Team

Each time when we run automation tests, we will have test results to view details about no. of tests passed, failed and failure details etc. And few reports also include test failure screenshots. We have discussed selenium examples on Extent report and testng custom report with screenshots.

SoftAssert in TestNG example

testng soft assert example

SoftAssert in TestNG helps to collect all the assertions throughout the @Test method. And to see assertions result at the end of the test, we have to invoke assertAll().

SoftAssert don't throw an exception when an assert fails. The test execution will continue with the next step after the assert statement.

If we use normal asserts like Assert.assertTrue() or Assert.assertEquals() in TestNG, @Test Method will immediately fail after any of the Asserts fails.

IMethodInterceptor examples to reorder list of test methods

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 methods, ITestContext context)', 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.

Execute Testng.xml using batch file

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.

Customize TestNG html Report

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

When ever we execute tests with TestNG, it will generate a default html report with basic information.

Optional annotation in TestNG

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.

Passing data to DataProvider from Excel sheet

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.