TestNG Framework inwards Selenium Part-2

TestNG Framework inwards Selenium Part-2

Introduction to TestNG Testing Framework
I) Overview

II) Install TestNG too write First TestNG Test Case

III) Create multiple Test Cases too execute
---------------------------------------------
TestNG Framework inwards Selenium Part-2

IV) Executing multiple programs / classes using XML file

V) Grouping Test Cases

VI) Parallel Test Execution
-------------------------------------------------
IV) Executing multiple programs / classes using XML file

Tags inwards XML

<suite get upwards = "Suite Name">
  <test get upwards ="Test Name">
    <classes>
      <class get upwards = "package.Class1Name"/>
      <class get upwards = "package.Class2Name"/>   
</classes>
</test>
</suite>
----------------------------------------------
Create XML file

Select Java project/Package > Right click > New > Other...
> Enter TestNG too Select TestNG Class
> Enter rootage too bundle names
> Enter XML file Name
----------------------------------
XML File
<suite name="Ecommerce">
  <test name="SanityTests">
    <classes>
      <class name="abcd.NewTest1"/>
      <class name="abcd.NewTest2"/>
    </classes>
  </test>
</suite>
---------------------------
Class 1

public degree NewTest1 {
@BeforeClass
public void login(){
System.out.println("Login Successful");
}
@AfterClass
public void logout(){
System.out.println("Logout Successful");
}
@Test (priority = 1)
public void addVendor(){
System.out.println("Add Vendor Successful");   
}
@Test(priority = 2)
public void addProduct(){
System.out.println("Add Product Successful");   
}
@Test(priority = 3)
public void addCurrency(){
System.out.println("Add Currency Successful");   
}
}
----------------------------------
Class 2


@BeforeClass
public void login(){
System.out.println("Login Successful");
}
@AfterClass
public void logout(){
System.out.println("Logout Successful");
}
@Test (priority = 1)
public void deleteVendor(){
System.out.println("Delete Vendor Successful");   
}
@Test(priority = 2)
public void deleteProduct(){
System.out.println("Delete Product Successful");   
}
@Test(priority = 3)
public void deleteCurrency(){
System.out.println("Delete Currency Successful");   
}
}
-----------------------------------
TestNG Annotations

@Test - The annotated method is a operate of a Test Case

@BeforeMethod - The annotated method volition live on run earlier each Test method
@AfterMethod - The annotated method volition live on run later each Test Method

@BeforeClass - The annotated method volition live on run earlier the showtime exam method inwards the electrical flow degree is

invoked.
@AfterClass - The annotated method volition live on run later all the Test methods inwards the electrical flow degree convey

been run.

@BeforeTest - The annotated method volition live on run earlier whatsoever Test method belonging to classes within

the tag is run
@AfterTest - The annotated method volition live on run later all the Test methods belonging to the classes

inside the tage convey run.
-----------------------------------------------------
V) Grouping Test Cases

XML File

<suite name="Suite" >
  <test name="Test">
  <groups>
  <run>
  <include get upwards = "regression"/>
  </run>
  </groups>
    <classes>
      <class name="abcd.NewTest3"/>
      </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
---------------------------------------------

Class File

public degree NewTest3 {
@Test(groups = {"sanity", "regression"}, priority =1)
public void login(){
System.out.println("Login Successful");
}
@Test (groups = {"sanity"}, priority =3)
public void fundTransfer(){
System.out.println("Fund Transfer Successful");
}
@Test(groups = {"sanity"}, priority =2)
public void search(){
System.out.println("Search Successful");
}
@Test (groups = {"regression"}, priority =2)
public void advancedSearch(){
System.out.println("Advanced Search Successful");
}
@Test(groups = {"regression"}, priority =3)
public void prePaidRecharge(){
System.out.println("PrePaid Recharge Successful");
}
@Test(groups = {"regression"}, priority =4)
public void billPayments(){
System.out.println("Bill Payments Successful");
}
@Test(groups = {"sanity", "regression"}, priority =10)
public void logout(){
System.out.println("Logout Successful");
}
}
-------------------------------------
VI) Parallel Test Execution

1) Parallel Test Execution (Methods)
XML File

<suite name="Suite" parallel="methods" thread-count ="3">
  <test name="Test">
    <classes>
      <class name="abcd.NewTest5"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Class File

public degree NewTest5 {
@Test
public void testCase1(){
long id = Thread.currentThread().getId();
System.out.println("Test Case i is Successful - Thread id is: "+ id);     
}
@Test
public void testCase2(){
long id = Thread.currentThread().getId();
System.out.println("Test Case two is Successful - Thread id is: "+ id);     
}
@Test
public void testCase3(){
long id = Thread.currentThread().getId();
System.out.println("Test Case three is Successful - Thread id is: "+ id);     
}
}

---------------------------------------------------- 
Note: Influenza A virus subtype H5N1 Thread is a concurrent unit of measurement of execution.
------------------------------------
2) Parallel Test Execution (Classes)

XML File

<suite name="Suite" parallel="classes" thread-count ="2">
  <test name="Test">
    <classes>
      <class name="abcd.NewTest5"/>
      <class name="abcd.NewTest6"/>
      </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
---------------------------------------------
Class i File

public degree NewTest5 {
@Test
public void testCase1(){
long id = Thread.currentThread().getId();
System.out.println("Test Case i is Successful - Thread id is: "+ id);     
}
@Test
public void testCase2(){
long id = Thread.currentThread().getId();
System.out.println("Test Case two is Successful - Thread id is: "+ id);     
}
@Test
public void testCase3(){
long id = Thread.currentThread().getId();
System.out.println("Test Case three is Successful - Thread id is: "+ id);     
}
}
---------------------------------------
Class two File

public degree NewTest6 {
@Test
public void testCase4(){
long id = Thread.currentThread().getId();
System.out.println("Test Case iv is Successful - Thread id is: "+ id);     
}
@Test
public void testCase5(){
long id = Thread.currentThread().getId();
System.out.println("Test Case five is Successful - Thread id is: "+ id);     
}
@Test
public void testCase6(){
long id = Thread.currentThread().getId();
System.out.println("Test Case half dozen is Successful - Thread id is: "+ id);     
}
}
----------------------------------------------------

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post