Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
December 13, 2016

Adding Classes to testng.xml file





Adding Classes to testng.xml file, will explain you about creating and configuring TestNG test suite with classes which are developed/created in the java project. A Class may contain one or more methods in it. With this testng.xml configuration file we can include all the methods belongs to a particular class to the test suite.

Below are The Steps for Adding Classes to testng.xml file:

1.Create a java project with multiple classes in each package.

1. Project with Multiple Classes

2.In the above project; created 3 packages called (com.test.firstpackage, com.test.secondpackage and          com.test.thirdpackage) and each package had 2 classes.

3.Now create a testng.xml file (here the xml file name is “testng-classes.xml”)  

with below  code/configuration content.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="ClassTest">
    <classes>
      <class name="com.test.firstpackage.FirstClassInFirstPackage"/>
      <class name="com.test.firstpackage.SecondClassInFirstPackage"/>
      <class name="com.test.secondpackage.FirstClassInSecondPackage"/>
      <class name="com.test.secondpackage.SecondClassInSecondPackage"/>
      <class name="com.test.thirdpackage.FirstClassInThirdPackage"/>
      <class name="com.test.thirdpackage.SecondClassInThirdPackage"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite →


In the above code, Classes will be reside in the “classes” tag and the each individual class will be in the “class” tag with “name” attribute.


4.Now execute the “testng-classes.xml” file from eclipse as TestNG suite. Then you can see the following output.

2. Multiple Classes Test Result

This way we can configure the classes in the testng xml configuration file to execute the scripts as classes and can analyse the test results.




Share this post: on Twitter on Facebook

Adding Packages to testng.xml file Adding Methods to testng.xml file

Related Posts

Excel to DataProvider

TestNG

Read data from Excel to DataProvider in Selenium

Running TestNG programmatically

TestNG

Running TestNG Tests Programmatically

EXECUTING ONLY FAILED TESTS

TestNG

Executing Only Failed Tests in TestNG

Capture Screenshot for Failed Tests

TestNG

Capture Screenshot for Failed Tests in TestNG

Preserve Order in TestNG

TestNG

Preserve Order in TestNG

PRIORITIZING TESTS

TestNG

Prioritizing Tests in TestNg

EXECUTE MULTIPLE XML FILES

TestNG

Execute Multiple XML files in TestNG

CUSTOM REPORTER IN TESTNG (1)

TestNG

Custom Reporter in TestNG

CUSTOM LOGGER IN TESTNG

TestNG

Custom Logger in TestNG

ASSERTIONS

TestNG

TestNG Assertions

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025