SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Configure testng.xml In Eclipse For Selenium WebDriver To Run All Or Specific Package

TestNG is very useful and powerful framework for selenium webdriver. We need to configure our tests based on our requirements or test scenarios. We are going very slowly with TestNG framework to understand each and everything clearly with examples so that it can help you to configure your test in any king of situations. In my previous posts, we have learnt about HOW TO RUN SPECIFIC CLASS FROM DIFFERENT PACKAGE USING testng.xml and HOW TO RUN SINGLE OR MULTIPLE CLASSES FROM ONE PACKAGE USING testng.xml. So now you can configure your testng.xml file to run any specific class from any package if you have read both previous posts.

Configure TestNGOne Project In Eclipse
In testng.xml file, You can also configure to run specific package or all packages of project. Let we see both examples. First of all, Create bellow given three packages with required classes, methods and code same as described in my PREVIOUS POST.

  1. TestNGOnePack(package) -> BaseClassOne.java, ClassOne.java, ClassTwo.java
  2. TestNGTwoPack(package) -> ClassOne.java, ClassTwo.java
  3. TestNGThreePack(package) -> ClassOne.java, ClassTwo.java
So now your project structure should be as shown in bellow given image.



Configure testng.xml to run selected packages from all packages of webdriver project in single test suite
From three packages, I wants to run only two packages -> "TestNGTwoPack" and "TestNGThreePack". For that we need to configure testng.xml as bellow.

<suite name="Suite One">
 <test name="Test One" >
  <packages>
   <package name="TestNGTwoPack" />
   <package name="TestNGThreePack" />
  </packages>
 </test> 
</suite>

In above given testng.xml code, <packages> tag packages is used to describe group of packages and <package> tag package is used to add specific package in our test suite. So when you run above testng.xml file, It will run only targeted two packages(TestNGTwoPack, TestNGThreePack). Other (TestNGOnePack)package(s) will be excluded from execution. Execution report will looks like bellow.

As you see, "TestNGOnePack" package is not executed as shown in above report image.

Configure testng.xml to run all packages of project in single test suite
If you wants to run all packages of your project, you can configure your testng.xml using wildcard(.*) with package tag as bellow.

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

Above given testng.xml file will execute all packages of your selenium webdriver project and test result report will looks like bellow.


As you see in report, Now all the packages are executed. This way, we can use wild card to include all webdriver test packages in our test.

1 comment: