testng.xml : Creating WebDriver Test Suite Using Classes From Different Packages

Now yous are already aware most HOW TO CREATE testng.xml FILE to configure as well as run your webdriver test. The primary argue behind popularity of TestNG framework for webdriver is nosotros tin plough over the axe configure our seek every bit per our requirements. I convey listed some Similarities/Differences betwixt Junit as well as TestNG framework In THIS POST. In my previous post, We convey already seen illustration of how to configure testng.xml file to run single/multiple webdriver seek classes of same package. Now permit me exhibit yous an illustration of how to create seek suite using classes from dissimilar packages.

First of all permit nosotros practice novel packages as well as classes every bit described inwards bellow given iii steps.

Step 1. Create packet = "TestNGOnePack" amongst classes = BaseClassOne.java, ClassOne.java and ClassTwo.java just every bit described inwards my PREVIOUS POST.

Step 2. Create packet = "TestNGTwoPack" nether same projection as well as add ClassOne.java and ClassTwo.java files amongst bellow given code lines.

ClassOne.java
package TestNGTwoPack;  import org.testng.annotations.Test;  world degree ClassOne extends TestNGOnePack.BaseClassOne{     @Test   world void testmethodone() {     String championship = driver.getTitle();     System.out.print("\nCurrent page championship is : "+title);     String Workdir = System.getProperty("user.dir");     String Classpackname = this.getClass().getName();     System.out.print("\n'"+Workdir+" -> "+Classpackname+" -> testmethodone' has been executed successfully");   } }

ClassTwo.java
package TestNGTwoPack;  import org.testng.annotations.Test;  world degree ClassTwo extends TestNGOnePack.BaseClassOne{     @Test   world void testmethodone() {   driver.navigate().to(" ");   String championship = driver.getTitle();   System.out.print("\nCurrent page championship is : "+title);   String Workdir = System.getProperty("user.dir");   String Classpackname = this.getClass().getName();   System.out.print("\n'"+Workdir+" -> "+Classpackname+" -> testmethodone' has been executed successfully");   } }

Above given both classes are inherited from TestNGOnePack.BaseClassOne to purpose webdriver instance, initialization as well as closing the webdriver.

Step 3. Create packet = "TestNGThreePack" nether same projection as well as add ClassOne.java and ClassTwo.java files amongst higher upward given code lines. You quest to modify packet parent inwards both class(TestNGTwoPack to TestNGThreePack) to purpose them inwards "TestNGThreePack" package.

So now, my packet as well as degree hierarchy is every bit bellow for projection TestNgOne.


Now supposing I practice non desire to execute all degree of all packages as well as I wants to execute alone few of them like TestNGOnePack.ClassOne, TestNGTwoPack.ClassTwo, TestNGThreePack.ClassOne and TestNGThreePack.ClassTwo. How tin plough over the axe nosotros practice that? You quest to configure your testng.xml file every bit bellow.
<suite name="Suite One">  <test name="Test One" >   <classes>    <class name="TestNGOnePack.ClassOne" />    <class name="TestNGTwoPack.ClassTwo" />    <class name="TestNGThreePack.ClassOne" />    <class name="TestNGThreePack.ClassTwo" />     </classes>  </test>  </suite>

Above given file volition run alone described iv classes out of amount half-dozen classes nether unmarried seek (Test One). You tin plough over the axe separate them inwards multiple tests likewise every bit described inwards my previous post.

Now execute higher upward given testng.xml file as well as verify result. It volition looks similar every bit shown inwards bellow given image.


This means nosotros tin plough over the axe configure our seek suite using alone specific degree from dissimilar packages.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post