How to Execute Multiple TestNG Class In Selenium

Posted By : Nargis Khan | 25-Apr-2018

In Java, we have the main method to call functions or method in another. I explain with an example:


i)  Create ClassA with "Add" method and ClassB with "Sub" method.
ii)  Then create ClassC with the main method.
iii)  For calling "Add" and "Sub" method in ClassC, I have to create Objects of ClassA and ClassB.
vi) So that's the way we can run multiple classes or methods

 

Now As we all know TestNG has no main Method. These classes work with annotations. Let's suppose you have 100 classes and you want to execute one by one. we can execute each class one by one. But that's not a good practice. 

 

We have to execute these classes by combining it. For combining we have to create an XML template file. Let's start creating an XML file.

 

Here I have a project and I am going to create 4 TestNG classes.

 

1) i) Go to Project-> then source.
ii) Just click on File to create a new one.


iii) I am giving the file name as TestNG.xml.
iv) Click on Finish. That file is displayed inside the src folder.

 

2) i) Click on that file and open it.
ii) Add these XML lines in the file which is given below.

 

<?xml version="1.0" encoding="UTF-8"?>
<suite name="example suite 1" verbose="1" >
  <test name="Regression suite 1" >
    <classes>
      <class name="com.first.example.demoOne"/>
      <class name="com.first.example.demoTwo"/>
      <class name="com.second.example.demoThree"/>
    </classes>
 </test>
</suite>
        

 


iii) The class name should be in "Packagename.classname" format.

 

3) Now you have to just execute this TestNG.xml file and all the class will start executing.
i) Right click on TestNG.xml file.
ii) Execute from "TestNG Suite".

 

4) Here you can see that I am able to execute all the classes at one click.

i) Result in form TestNG Report:

 

ii) The result of a running suite:

 

Related Tags

About Author

Author Image
Nargis Khan

Nargis is certified in Manual Testing , she has done B.Tech in computer science. Her Hobbies are reading books & listening music.

Request for Proposal

Name is required

Comment is required

Sending message..