Include/Exclude Only Selected Test Methods In Selenium WebDriver-TestNg Test Suite Using testng.xml

If yous are using selenium webdriver amongst TestNg framework hence yous tin easily run your selected examination methods from selected classes. Supposing yous convey a ii classes inwards your packet in addition to outset shape convey iii examination methods in addition to minute shape convey 5 examination methods. Now yous wants to run exclusively i examination method from first class in addition to ii examination methods from minute shape hence yous tin configure it really easily inwards testng.xml file. In sort, yous tin include or exclude selected examination methods from execution. Let me present yous how to create it amongst uncomplicated webdriver test configured past times testng.xml file.

Configure TestNGOne Project In Eclipse
  1. First of all, Configure TestNGOne projection inwards eclipse every bit described inwards PREVIOUS POST.
  2. Add testmethodtwo() bellow the testmethodone() every bit shown bellow inwards ClassOne.java and ClassTwo.java file of all iii packages.
public shape ClassTwo extends TestNGOnePack.BaseClassOne{     @Test   populace 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");   }           //Add testmethodtwo() here  @Test  populace void testmethodtwo() {      driver.findElement(By.xpath("//input[@value='female']"));      String Workdir = System.getProperty("user.dir");      String Classpackname = this.getClass().getName();      System.out.print("\n'"+Workdir+" -> "+Classpackname+" -> testmethodtwo' has been executed successfully");   } }

Now your TestNGOne project's construction volition looks similar bellow.


Configure testng.xml file to Include in addition to run selected webdriver examination methods from few classes
Now supposing, I wants to run only

  • testmethodone() method from TestNGOnePack -> ClassOne.java
  • testmethodone() and testmethodtwo() methods from TestNGTwoPack -> ClassTwo.java
  • testmethodone() in addition to testmethodtwo() methods from TestNGThreePack -> ClassOne.java
  • testmethodone() in addition to testmethodtwo() methods from TestNGThreePack -> ClassTwo.java
To perform inwards a higher house action, I convey to configure my testng.xml file every bit bellow.

<suite name="Suite One">   <test name="Test One" >     <classes>         <class name="TestNGOnePack.ClassOne" />           <methods>              <include name="testmethodone" />           </methods>       <class name="TestNGTwoPack.ClassTwo" />             </classes>        <packages>              <package name="TestNGThreePack" />        </packages>     </test>  </suite>

In inwards a higher house given testng.xml file, methods in addition to include tags are novel to learn. You tin read virtually TestNg Framework's <suite>, <test>, <classes> in addition to <class> tags inwards THIS POST and <packages>, <package> tags inwards THIS POST. <methods> tag defines the grouping of methods and <include> tag defines which method yous wants to include inwards execution. Now execute this testng.xml file in addition to verify the number report.


If yous come across inwards in a higher house result, Only examination testmethodone() is executed from TestNGOnePack -> ClassOne.java. This agency nosotros tin include whatever specific method inwards our examination suite to execute from whatever class.

Configure testng.xml file to exclude specific examination method from class
Sameway, To exclude specific examination method from class, We tin purpose <exclude> tag within <methods> tag every bit bellow.

<suite name="Suite One">   <test name="Test One" >     <classes>         <class name="TestNGOnePack.ClassOne" />           <methods>               <include name="testmethodone" />           </methods>        <class name="TestNGTwoPack.ClassTwo" />          <methods>               <exclude name="testmethodone" />           </methods>             </classes>        <packages>              <package name="TestNGThreePack" />        </packages>     </test>  </suite>

When yous run inwards a higher house given testng.xml file, it volition exclude testmethodone() examination method of TestNGTwoPack -> ClassTwo.jav from execution in addition to volition execute only ClassTwo.java file every bit shown inwards bellow given examination number report.


This agency nosotros tin configure our testng.xml file to include or exclude whatever specific examination method from execution.

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