Test Configuration File / Executable File

In order to create a test suite and run separate test cases, we need framework which drives the automation. Here testng.xml can be called as "driver" which drives several test cases automated using selenium code.

Advantage of using TestNG with Selenium is of running multiple test cases from multiple classes using xml configuration file

Another advantage of testng.xml is for entire teams that need to share their test configuration or to be able to specify different parameters or subsets of their tests in different testng.xml files

testng.xml file will have the following structure:-

The root tag of this file is <suite>. as tag <html> which is root tag in html.
<suite> tag can contain one or more <test> tags.
<test> tag can contain one or more <classes> tags.
<classes> tag can contain one or more <method> tags

Here is an example testng.xml file:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
  <suite name="ApplicationName Suite" verbose="1" >
  <test name="testpackage" >
       <class name="testpackage.Test" />
   <test name="Regression Testing">
      <class name="testpackage.app.classSample"/>
      <class name="testpackage.app.locationTest"/>


We can specify package names instead of class names in testng.xml file:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name=" ApplicationName Suite" verbose="1" >
  <test name="Regression1"   >
      <package name="testpackage" />


In this example, TestNG will look at all the classes in the package “testpackage” and will retain only classes that have TestNG annotations.

We can also specify group tags and method tags to be included and excluded:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name=" ApplicationName Suite" verbose="1" >
<test name="Regression1">
      <exclude name="brokenTests"  />
      <include name="checkinTests"  />
    <class name="test.IndividualMethodsTest">
        <include name="testMethod" />


TestNG examples with Class Names

TestNG example with Package Names

You can also define new groups inside testng.xml and specify additional details in attributes, such as whether to run the tests in parallel, how many threads to use, whether you are running JUnit tests, etc...                                                 

By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictable order, set the preserve-order attribute to false

Selenium Tutorials: 


Where to place the XML file?

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.