Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 10: What Is Package Tag And How To Use In TestNG.XML?

Posted on 02/19/2025 By admin

Hello Folks,

When we generate a testng.xml for TestNG classes of a package, we see all class names (with at least one @Test annotated method) of that package under “class” tag wrapped by tag.

We can see an example below:

When we have multiple packages in a project , testng.xml includes all TestNG classes from all packages within single tag with multiple tags as below:

You can learn more about generation of testng.xml in this post.

In above testng.xml you can see every class name is prefixed by package name i.e. packageName.className which is also not in order. All classes from all packages are mixed in testng.xml as you can see in above pic. If there are many packages, you may be confused. Suppose, if you need to remove all classes of specific package, it will be difficult. So for better categorization, TestNG provides you and tags.

All class names of each package are grouped within separate package tag first and then all package names are combined within tag. tag is a container which contains multiple tags. It is similar to nesting of and tag.

To generate a testng.xml using package tag, you just need to select “Packages” in Class selection drop-down in testng.xml generation window as shown below:

It will include all classes of those packages for testng suite. Remember here we do not have option to select classes to run when we use package tag. You lose that flexibility here.

If you want to include all packages, TestNG allows you to use expressions in stead of multiple tags as below:

You just need to use star (*) with dot(.). Dot indicates current project directory while star represents all package names in current directory.

Note: You can not use same concept in case of classes as below:

If you run above testng.xml you will get org.testng.TestNGException: Cannot find class in classpath exception because it will search for a class with name “.*”.

So, if you want to run all classes of all packages in a Project, it is good to use tags.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below. If you like my posts, please like, comment, share and subscribe. #ThanksForReading

#HappySelenium

Uncategorized

Post navigation

Previous Post: Validate The Validation You Do – isEnabled() & isSelected() Methods in Selenium WebDriver
Next Post: Do You Know That Class ExpectedConditions is Not To Just Use With WebDriverWait?

Related Posts

Selenium Topics – Page 8 – Make Selenium Easy Uncategorized
scrollTo500 – Make Selenium Easy Uncategorized
Learn Selenium With Quiz – Basic Level 5 Uncategorized
Locating Dynamic Web Elements In Selenium WebDriver : Conditional Xpaths And CSS Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized
May 2018 – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark