Include/Exclude Selenium WebDriver Test Package From Test Suite Using testng.xml

Now you are already aware about HOW TO INCLUDE OR EXCLUDE SELECTED TEST METHODS IN TEST SUITE. Now our next tutorial is about how to include or exclude selected package from execution of test suite. Supposing you have multiple packages in your webdriver test suite and you wants to run only specific selected package then how will you do it? Let we look at simple example for the same.

First of all configure project "TestNGOne" with 3 packages as described in my previous post.

Configuring testng.xml file to include only specific package in test suite from multiple packages
As described in my THIS POST, we can use wildcard(.*) with package tag to run all packages but then immediately we will use include to run specific package from all the packages as bellow.

<suite name="Suite One">
  <test name="Test One" >
     <packages>
        <package name=".*">
           <include name="TestNGOnePack" />
        </package>
     </packages>
  </test>
</suite>

When you run above given testng.xml file, it will run only "TestNGOnePack" package from all packages of "TestNGOne" project. Look at bellow given TestNg result report.


If you see in above test result of webdriver testng suite, only classes and methods of "TestNGOnePack" package are executed. remaining 2 packages(TestNGTwoPack and TestNGThreePack) are not executed.

Configuring testng.xml file to exclude specific package from execution
To exclude specific package from execution, You need to configure your testng.xml file as bellow. Supposing I wants to exclude "TestNGThreePack" package from execution.
<suite name="Suite One">
  <test name="Test One" >
  <packages>
   <package name=".*">
    <exclude name="TestNGThreePack" />
   </package>
  </packages>
 </test>
</suite>

Above given testng.xml file with exclude "TestNGThreePack" package from execution and will execute remaining two packages as shown in bellow given report image.


This way we can include or exclude full package from execution.

2 comments: