How To Group And Run Selenium Test Cases Using Testng

Grouping tests Is roughly other real proficient feature of testng using which you lot tin create grouping of examine methods. You tin practice a grouping of examine methods based on functionality together with features, or based on modules or based on testing types similar functional testing, sanity testing etc.. This way you lot can differentiate specific group examine methods from all examine methods.

Benefits of grouping
Supposing you lot accept xx unlike examine methods In unmarried examine instance together with from them you lot wants to run alone those examine methods which are related to checking E-Mail. You tin practice It real easily using testng grouping characteristic equally bellow example.

Create bellow given course of teaching file nether your projection In eclipse

Grouping.java
package Testing_Pack;  import org.testng.annotations.Test;  world course of teaching Grouping {  //"check-mail" grouping examine method.  @Test(groups={"check-mail"}, priority =0)  world void logIn(){  System.out.println("Log In.");  }    //Do non accept whatsoever group.  @Test  world void viewNews(){  System.out.println("Viewing News.");  }    //"check-mail" grouping examine method.  @Test(groups={"check-mail"}, priority =1)  world void checkMail(){  System.out.println("Checking Mail.");  }    //"check-mail" grouping examine method.  @Test(groups={"check-mail"}, priority =2)  world void logOut(){  System.out.println("Logout.");  } }

In higher upwards example, You tin come across that @Test methods logIn(), checkMail() and logOut() has groups attribute alongside same value "check-mail". That way all these three @Test methods are of same group. Now If I wants to execute alone "check-mail" grouping @Test methods together with therefore I accept to configure my testng.xml file equally bellow.

testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Group Test Suite" verbose="1">   <test name="Group Test" >         <groups>   <run>    <include name="check-mail" />   </run>  </groups>    <classes>   <class name="Testing_Pack.Grouping" />  </classes>   </test> </suite>

In higher upwards xml file, I accept used ii novel tags. <groups> and <run>.  <groups> tag defines the grouping and </run> tag represents the grouping that needs to live on run. include tag describes which grouping needs to live on executed. Above xml volition alone execute those examine methods which are available In course of teaching = Testing_Pack.Grouping and @Test methods which accept grouping name="check-mail". That way alone logIn(), checkMail() and logOut() volition live on executed together with viewNews() method volition live on non executed.

You tin VIEW ADVANCED TUTORIALS ON TESTNG.

Execution effect volition looks similar bellow.
This way, Testng grouping characteristic tin attention you lot to execute alone specific grouping tests.
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