TestNG Framework for Selenium

TestNG Framework for Selenium
 

TestNG Framework
1) TestNG Introduction

2) Benefits of TestNG

3) TestNG Installation

4) TestNG Test Case example

5) Create multiple Test Cases.
-----------------------------------
6) Execute multiple programs/Classes using XML file.
 

Create XML File
Select Java Project as well as Right Click
> New > Other
> Enter XML as well as guide XML file
> Enter File Name
> Finish
--------------------------
Tags

suite tag

test tag

classes tag

class tag (multiple)
-------------------
XML File:
<suite cite = "Ecommerce suite">
<test cite = "Sanity Tests">
<classes>
<class cite = "seleniumTests.Class1"/>
<class cite = "seleniumTests.Class2"/>
</classes>

</test>
</suite>
-----------------
Class 1
public bird Class1 {
    @BeforeTest
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterTest
    populace void logout(){
    System.out.println("Logout Successful");
    }
    @Test (priority = 1)
    populace void search(){
    System.out.println("Search Successful");
    }
    @Test (priority = 2)
    populace void advancedSearch(){
    System.out.println("Advanced Search Successful");
    }
    @Test (priority = 3)
    populace void buyProducts(){
    System.out.println("Buying Products Successful");
    }
    }
--------------------------------------------
Class 2
public bird Class2 {
    /*@BeforeClass
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterClass
    populace void logout(){
    System.out.println("Logout Successful");
    }*/
    @Test (priority = 1)
    populace void accountSummary(){
    System.out.println("Account Summary Successful");
    }
    @Test (priority = 2)
    populace void fundTransfer(){
    System.out.println("Fund Transfer Successful");
    }
    @Test (priority = 3)
    populace void billPayment(){
    System.out.println("Bill Payment Successful");
    }
    }
-----------------------------------------
TestNG Annotations
 

@Test -Makes Method equally Test Case

@BeforeMethod - Pre-condition for every Test Case inwards a Class
@AfterMethod -Post-condition for every Test Case inwards a Class

@BeforeClass -Pre-condition for all Test Cases inwards a Class
@AfterClass -Post-condition for all Test Cases inwards a Class

@BeforeTest - Pre-condition for all Test Cases inwards multiple Class
@AfterTest - Post-condition for all Test Cases inwards multiple Class
--------------------------------------
7) Parallel Test execution
 

> Parallel Test execution using TestNG (using unmarried machine/Computer)

> Parallel Test execution using Selenium Grid (using multiple machines/Computer)
-------------------------------------------------
Class 1
public bird Class1 {
    @BeforeTest
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterTest
    populace void logout(){
    System.out.println("Logout Successful");
    }
    @Test (priority = 1)
    populace void search(){
    System.out.println("Search Successful");
    }
    @Test (priority = 2)
    populace void advancedSearch(){
    System.out.println("Advanced Search Successful");
    }
    @Test (priority = 3)
    populace void buyProducts(){
    System.out.println("Buying Products Successful");
    }
    @Test (priority = 4)
    populace void testCase(){
    System.out.println("Test Case inwards "+getClass().getSimpleName()
    + " With Thread id: " + Thread.currentThread().getId());
    }
    }
-----------------------------------------

Class 2

public bird Class2 {
    /*@BeforeClass
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterClass
    populace void logout(){
    System.out.println("Logout Successful");
    }*/
    @Test (priority = 1)
    populace void accountSummary(){
    System.out.println("Account Summary Successful");
    }
    @Test (priority = 2)
    populace void fundTransfer(){
    System.out.println("Fund Transfer Successful");
    }
    @Test (priority = 3)
    populace void billPayment(){
    System.out.println("Bill Payment Successful");
    }
    @Test (priority = 4)
    populace void testCase(){
    System.out.println("Test Case inwards "+getClass().getSimpleName()
    + " With Thread id: " + Thread.currentThread().getId());
    }
}
---------------------------------------
XML File
<suite cite = "Parallel Test suite" parallel = "classes" thread-count = "2">
<test cite = "Sanity Test">

<classes>
<class cite = "seleniumTests.Class1"/>
<class cite = "seleniumTests.Class2"/>
</classes>

</test>
</suite>
--------------------------------------------------------
parallel = "methods": TestNG volition run all the methods inwards carve upwards threads.
parallel = "classes" : TestNG volition run all the methods inwards the same bird inwards the same thread.
parallel = "tests" : TestNG volition run all the methods inwards the same <test> tag inwards the same thread.
---------------------------------------
Class 1
3 Methods thread(1) 1
Class 2
3 methods thread(1) 2
----------------------
Class 1
3 Methods thread(3) 1
Class 2
3 methods thread(3) 2
-----------------------------
8) Grouping Test Cases
 

Class File
@BeforeTest (groups ={"sanity","regression"})
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterTest (groups ={"sanity","regression"})
    populace void logout(){
    System.out.println("Logout Successful");
    }
   
    @Test (groups ={"sanity"})
    populace void search(){
    System.out.println("Search Successful");
    }
    @Test (groups ={"sanity","regression"})
    populace void advancedSearch(){
    System.out.println("Advanced Search Successful");
    }
    @Test (groups ={"sanity", "regression"})
    populace void buyProducts(){
    System.out.println("Buying Products Successful");
    }
    @Test (groups ={"regression"})
    populace void abcd(){
    System.out.println("Abcd Successful");
    }
    @Test (groups ={"regression"})
    populace void xyza(){
    System.out.println("Xyza Successful");
    }
    @Test (groups ={"regression"})
    populace void asdf(){
    System.out.println("Asdf Successful");
    }
}
-----------------------------
XML File
<suite cite ="suite">
<test cite ="test">

<groups>
<run>
<include cite = "sanity"/>
</run>
</groups>

<classes>
<class cite = "seleniumTests.GroupTests"/>
<class cite = "seleniumTests.GroupTests2"/>
</classes>

</test>
</suite>
----------------------------------------------------------------
9) Data driven testing using DataProvider Annotation
 

If y'all desire locomote amongst excel, thence download 3rd political party jounce files

Ex: jxl

public bird DataDriven {
    @Test (dataProvider="testdata")
    populace void Addition(String val1, String val2, String val3){
        int a = Integer.parseInt(val1);
        int b = Integer.parseInt(val2);
        int c = Integer.parseInt(val3);
        int consequence = a + b + c;
        System.out.println(result);
    }
   
@DataProvider(name="testdata")
    populace Object [] [] readExcel() throws BiffException, IOException {
        File f = novel File("C:/Users/gcreddy/Desktop/Input.xls");
        Workbook w = Workbook.getWorkbook(f);
        Sheet second = w.getSheet(0);
        int rows = s.getRows();
        int columns = s.getColumns();
        //System.out.println(rows);
        //System.out.println(columns);
        String Inputdata [] [] = novel String [rows] [columns];
        for (int i = 0; i<rows; i++){
            for (int j = 0; j<columns; j++){
                Cell c = s.getCell(j, i);
                Inputdata [i] [j] = c.getContents();
                //System.out.println(Inputdata[i][j]);
            }
        }
        furnish Inputdata;
        }
}
----------------------------------------------------------
Assignment
--------------
Read Test Data (5 sets) from external Excel file as well as perform Data Driven Testing for Gmail Login Functionality.

Steps:

i) Prepare Test Data file (with five sets of electronic mail as well as Passwords)

ii) using DataProvider Annotation read the data.

iii) Use the information inwards TestNg assay out cases.
-------------------------------------------------
Selenium Project Work
 

Java Programming + Selenium WebDriver + TestNG Framework

Domain: Ecommerce

Sub-Domain: B2C

Application: Online Shopping

Development Environment: LAMP (Linux, Apache, MySQL as well as PHP)

Testing Environment: Intranet

Production Environment: Internet
------------------------------
Two interfaces of spider web Application

i) Admin Interface

ii) User Interface
---------------------------

Admin Interface URL: http://www.gcrit.com/build3/admin/

Username: admin

Password: admin@123

User Interface URL: http://www.gcrit.com/build3/

build3 -folder

http://telugu.greatandhra.com/

telugu -sub domain
------------------------------------------
Features to live on tested inwards User Interface

i) work an account

ii) Login

iii) Buy Product
------------------------------
Features to live on tested inwards Admin Interface

i) Login

ii) Create /Edit/Delete Products

iii) Insert / edit/delete vendors

iv) Create /Edit/Delete currencies
-------------------------------------------
Test Cases
Create an Account inwards User Interface

Steps:

i) Launch the Browser
ii) Navigate to http://www.gcrit.com/build3/
iii) click "create an account" link
iv) Enter all mandatory fields
v) Click "continue"
-------------
Verification Point:
Capture conformation message as well as compare amongst expected.
-----------------------------------------
Login inwards User Interface

Steps:

i) Launch the Browser
ii) Navigate to http://www.gcrit.com/build3/
iii) Click "login" link
iv) Enter "Email Address"
v) Enter "Password"
vi) Click "Sign in"

Verification point:

Capture Welcome message as well as abide by sub string source name
--------------------------------------------
Login inwards Admin Interface
i) Launch the Browser
ii) Navigate to http://www.gcrit.com/build3/admin/
iii) Enter "Username"
iv) Enter "Password"
v) Click "Login" button
------------------
Verification point:

Check the being of "logoff" link
----------------------------------------------

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