Manage Execution and Data with TestNG

When we want to write or run hundreds of test cases, we need to manage those with minimum effort. We can use JSON or XML files to read and edit data or parameters. use this method and you will see, how your management process more easily.

Now we add some parameters to the testng.xml file and we use these parameters at all classes.

For example; I run and write many test cases and I always use driver path, driver type, and base URL.

Step1: I added these parameters to testng.xml with parameter tag and enter name and value and I also added class names because I will use these parameters at these classes. We can add more than that of course.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="All Test Suite">
<test verbose="2" preserve-order="true" name="Command Line Tests" >
<parameter name="DRIVER_PATH" value="Drivers/chromedriver"></parameter>
<parameter name="DRIVER_TYPE" value=""></parameter>
<parameter name="BASE_URL" value=""></parameter>

<class name="FirstChromeSearch"></class>
<class name="ParallelTesting"></class>


Step2: We add these parameters to functions with Parameters and we need to add those as a value too.

public void beforeTest(String BASE_URL, String DRIVER_TYPE, String DRIVER_PATH) {
ChromeOptions options = new ChromeOptions();
System.setProperty(DRIVER_TYPE, DRIVER_PATH);
driver = new ChromeDriver(options);

I will run these test cases with a headless mode on the terminal. Now we won’t see any UI but this will save us time.

Now we go testng.xml’s path and run this command on the terminal:

mvn clean test -DsuiteXmlFile=testng.xml

After we ran this suite we can see results now.

Quality Assurance Engineer-Automation