Hybrid Framework Using UFT


Objective: Reduce Manual efforts in Smoke and Regression testing
When ever new deployment is done in QA or Staging
environment, we have to perform shakedown to make sure all the
major and basic functionality of the application are working as
expected and regression testing to make sure that the unchanged
areas of the application under test are working fine. If we are
doing it manually then It is a time consuming or tedious process.
To overcome this, a hybrid framework has been designed using
UFT tool which will perform the shakedown and regression testing
automatically. It will also provide the test case execution report
with screen shots attachment.

Tool Used : UFT (Unified Functional Testing)
Application Under Test : Flight Reservation (Dummy Application)
Script: VB Script

Hybrid Framework consists of :
1. Controller.xls (An excel file where we are controlling the test execution)
If the Run mode is 'Y' then the corresponding function will get executed.







“TestData” is a sheet in the Controller.xls where we are maintaining all our test data. We have considered Excel sheet as database and we are fetching test data by passing query. One Function i.e Fnc_ExtractData() has been written in GetDataFromExcel.qfl to fetch data from excel file which will be discussed later.



2. GetDataFromExcel.qfl (A function library has been written to fetch data
from excel by passing query)
'Function to fetch data from excel by passing SQL query
Public ObjCon
Public ObjRs
Public strExlPath
Function Fnc_ExtractData(strSqlStmt)
Set ObjCon = CreateObject("ADODB.Connection")
Set ObjRs = CreateObject("ADODB.Recordset")
strExlPath = Environment.Value("Excel_Path")
ObjCon.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" & strExlPath
& ";Readonly=True"

ObjRs.Open strSqlStmt,ObjCon
While ObjRs.EOF = False
data = ""
For i = 0 To ObjRs.Fields.Count-1 Step 1
data = data&" "&ObjRs.Fields(i)
Next
Fnc_ExtractData = data
ObjRs.MoveNext
Wend
Set ObjRs = Nothing
ObjCon.Close
Set ObjCon = Nothing
End Function

3. Keywords.qfl (A Function Library which contains all the keywords defined
in it)
Set v_ob_FR = Browser("Flight Reservation").Page("Flight Reservation")
'--------------------------- Close Application ----------------------------
Function Close_App()
Browser("Flight Reservation").Close
End Function
'---------------------------- Open Application ---------------------------
Function Fnc_OpenApp()
SystemUtil.Run "iexplore.exe","http://newtours.demoaut.com/"
End Function
'--------------------------- Login -----------------------------
Function Fnc_Login()
UserName = Trim(Fnc_ExtractData("Select UserName From [TestData$]"))
Password = Trim(Fnc_ExtractData("Select Password From [TestData$]"))

If v_ob_FR.WebEdit("userName").Exist Then
v_ob_FR.WebEdit("userName").Set UserName
If v_ob_FR.WebEdit("password").Exist Then
v_ob_FR.WebEdit("password").Set Password
If v_ob_FR.Image("Sign-In").Exist Then
v_ob_FR.Image("Sign-In").Click
v_ob_FR.Sync
wait(3)
v_Img_Login =
Environment.Value("v_st_Screenshot_Path")&"\Login.png"
v_ob_FR.CaptureBitmap v_Img_Login
If v_ob_FR.Link("SIGN-OFF").Exist Then
Reporter.ReportEvent micPass,"Login","Login Successful",v_Img_Login
Else
Reporter.ReportEvent micFail,"Login","Login Unsuccessful",v_Img_Login
End If
Else
Reporter.ReportEvent micFail,"Sign-In:Image","Sign-In:Image is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Password:Edit Field","Password:Edit Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"UserName:Edit Field","UserName:Edit Field is not displayed"
End If
End Function
'------------------------------ Booking A Ticket --------------------------
Function Fnc_BookTicket()

PassCount = Trim(Fnc_ExtractData("Select PassCount From [TestData$]"))
FlyFrom = Trim(Fnc_ExtractData("Select FlyFrom From [TestData$]"))
Dep_Month = Trim(Fnc_ExtractData("Select Dep_Month From [TestData$]"))
Dep_Date = Trim(Fnc_ExtractData("Select Dep_Date From [TestData$]"))
FlyTo = Trim(Fnc_ExtractData("Select FlyTo From [TestData$]"))
Arr_Month = Trim(Fnc_ExtractData("Select Arr_Month From [TestData$]"))
Arr_Date = Trim(Fnc_ExtractData("Select Arr_Date From [TestData$]"))
FirstName = Trim(Fnc_ExtractData("Select FirstName From [TestData$]"))
LastName = Trim(Fnc_ExtractData("Select LastName From [TestData$]"))
Airline = Trim(Fnc_ExtractData("Select Airline From [TestData$]"))
Meal = Trim(Fnc_ExtractData("Select Meal From [TestData$]"))
CardType = Trim(Fnc_ExtractData("Select CardType From [TestData$]"))
CC_Number = Trim(Fnc_ExtractData("Select CC_Number From [TestData$]"))
CC_EXP_Month = Trim(Fnc_ExtractData("Select CC_EXP_Month From [TestData$]"))
CC_EXP_Year = Trim(Fnc_ExtractData("Select CC_EXP_Year From [TestData$]"))

Address = Trim(Fnc_ExtractData("Select Address From [TestData$]"))
City = Trim(Fnc_ExtractData("Select City From [TestData$]"))
State = Trim(Fnc_ExtractData("Select State From [TestData$]"))
ZIP = Trim(Fnc_ExtractData("Select ZIP From [TestData$]"))
Country = Trim(Fnc_ExtractData("Select Country From [TestData$]"))
If v_ob_FR.WebRadioGroup("tripType").Exist Then
If v_ob_FR.WebRadioGroup("tripType").GetROProperty("selected item
index") = 2 Then
v_ob_FR.WebRadioGroup("tripType").Click
End If
If v_ob_FR.WebList("passCount").Exist Then
v_ob_FR.WebList("passCount").Select PassCount
If v_ob_FR.WebList("fromPort").Exist Then
v_ob_FR.WebList("fromPort").Select FlyFrom
If v_ob_FR.WebList("fromMonth").Exist Then
v_ob_FR.WebList("fromMonth").Select
If v_ob_FR.WebList("fromDay").Exist Then
v_ob_FR.WebList("fromDay").Select Dep_Date
If v_ob_FR.WebList("toPort").Exist Then
v_ob_FR.WebList("toPort").Select FlyTo
If v_ob_FR.WebList("toMonth").Exist Then
v_ob_FR.WebList("toMonth").Select Arr_Month
If v_ob_FR.WebList("toDay").Exist Then
v_ob_FR.WebList("toDay").Select Arr_Date
If v_ob_FR.WebRadioGroup("servClass").Exist Then
v_ob_FR.WebRadioGroup("servClass").Click
If v_ob_FR.WebList("airline").Exist Then
v_ob_FR.WebList("airline").Select Airline
If v_ob_FR.Image("findFlights").Exist Then
v_ob_FR.Image("findFlights").Click
v_ob_FR.Sync
If v_ob_FR.Image("buyFlights").Exist Then
v_ob_FR.Image("buyFlights").Click
v_ob_FR.Sync
If v_ob_FR.WebEdit("passFirst0").Exist Then
v_ob_FR.WebEdit("passFirst0").Set FirstName
If v_ob_FR.WebEdit("passLast0").Exist Then
v_ob_FR.WebEdit("passLast0").Set LastName
If v_ob_FR.WebList("pass.0.meal").Exist Then
v_ob_FR.WebList("pass.0.meal").Select Meal
If v_ob_FR.WebList("creditCard").Exist Then
v_ob_FR.WebList("creditCard").Select CardType
If v_ob_FR.WebEdit("creditnumber").Exist Then
v_ob_FR.WebEdit("creditnumber").Set CC_Number
If v_ob_FR.WebList("cc_exp_dt_mn").Exist Then
v_ob_FR.WebList("cc_exp_dt_mn").Select CC_EXP_Month
If v_ob_FR.WebList("cc_exp_dt_yr").Exist Then
v_ob_FR.WebList("cc_exp_dt_yr").Select CC_EXP_Year
If v_ob_FR.WebEdit("cc_frst_name").Exist Then
v_ob_FR.WebEdit("cc_frst_name").Set FirstName
If v_ob_FR.WebEdit("cc_last_name").Exist Then
v_ob_FR.WebEdit("cc_last_name").Set LastName
If v_ob_FR.WebEdit("billAddress1").Exist Then
v_ob_FR.WebEdit("billAddress1").Set Address
If v_ob_FR.WebEdit("billCity").Exist Then
v_ob_FR.WebEdit("billCity").Set City
If v_ob_FR.WebEdit("billState").Exist Then
v_ob_FR.WebEdit("billState").Set State
If v_ob_FR.WebEdit("billZip").Exist Then
v_ob_FR.WebEdit("billZip").Set ZIP
If v_ob_FR.WebList("billCountry").Exist Then
v_ob_FR.WebList("billCountry").Select Country
If v_ob_FR.WebCheckBox("ticketLess").Exist Then
v_ob_FR.WebCheckBox("ticketLess").Set "ON"
If v_ob_FR.Image("buyFlights").Exist Then
v_ob_FR.Image("buyFlights").Click
v_ob_FR.Sync
Wait(3)
v_img_Booking = Environment.Value("v_st_Screenshot_Path")&"\Booking.png"
v_ob_FR.CaptureBitmap v_img_Booking
If v_ob_FR.WebElement("Your itinerary has been booked!").Exist Then
Reporter.ReportEvent micPass,"Ticket Booking","Ticket Booking Successful",v_img_Booking
Else
Reporter.ReportEvent micFail,"Ticket Booking","Ticket Booking
Unsuccessful",v_img_Booking
End If
Else
Reporter.ReportEvent micFail,"SECURE PURCHASE:Image","SECURE PURCHASE:Image is not displayed"
End If

Else
Reporter.ReportEvent micFail,"Same as Billing Address:Check
Box","Same as Billing Address:Check Box is not displayed"
End If
Else
Reporter.ReportEvent
micFail,"Country:Dropdown","Country:Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Postal Code:Text Field","Postal Code:Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"State/Province:Text
Field","State/Province:Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"City:Text Field","City:Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Address:Text Field","Address:Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Credit Card Last Name:Test Field","Credit Card Last Name:Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Credit Card First Name:Test Field","Credit Card First Name:Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Credit Card Expiration
Year:Dropdown","Credit Card Expiration Year:Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Credit Card Expiration
Month:Dropdown","Credit Card Expiration Month:Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Number:Text Field","Number:Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Card Type:Dropdown","Card Type:Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Meal:Dropdown","Meal:Dropdown is not
displayed"
End If
Else
Reporter.ReportEvent micFail,"Last Name: Text Field","Last Name:
Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"First Name: Text Field","First Name: Text Field is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Continue:Image","Continue:Image is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Continue:Image","Continue:Image is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Airline:Dropdown","Airline:Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Business Class:Radio Button","Business Class:Radio Button is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Arrival Day: Dropdown","Arrival Day: Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Arrival Month: Dropdown","Arrival Month: Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Arriving In: Dropdown","Arriving In: Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Departure Day: Dropdown","Departure Day: Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Departure Month: Dropdown","Departure Month: Dropdown is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Departing From:WebList","Passengers:WebList is not displayed"
End If
Else
Reporter.ReportEvent
micFail,"Passengers:WebList","Passengers:WebList is not displayed"
End If
Else
Reporter.ReportEvent micFail,"Round Trip:Radio Button","Round Trip:Radio Button is not displayed"
End If
End Function

4. DriverScript (An action that Controls the test execution)
'------------------- Load Function Libraries -------------------------
LoadFunctionLibrary "H:\Flight_Reservation\Function_Libraries\Keywords.qfl"
LoadFunctionLibrary "H:\Flight_Reservation\Function_Libraries\Generic.qfl"
LoadFunctionLibrary
"H:\Flight_Reservation\Function_Libraries\GetDataFromExcel.qfl"
'------------------- Close All Excel Files ---------------------------
SystemUtil.CloseProcessByName "EXCEL.exe"

'------------------- Close All the Browsers --------------------------
Call Fnc_CloseBrowsers()
'------------------- Delete All the Files from the Images folder -----
Call Fnc_DeleteFiles(Environment.Value("v_st_Screenshot_Path"))
'------------------- Create an Excel Object --------------------------
Public ObjExcel
Public ObjSheet
Set ObjExcel = CreateObject("Excel.Application")
'------------------- Open Controller Sheet ---------------------------
ObjExcel.WorkBooks.Open Environment.Value("Excel_Path")
Set ObjSheet = ObjExcel.ActiveWorkbook.Sheets("Controller")
'------------------- Count the number of Rows & Column of Controller Sheet
-------------------------
row = ObjSheet.UsedRange.Rows.Count
col = ObjSheet.UsedRange.Columns.Count

For i = 2 To row Step 1
If Trim(ObjSheet.Cells(i,2).Value) = "Y" Then
FunctionName = Trim(ObjSheet.Cells(i,1).Value)
Select Case FunctionName
Case "Fnc_CloseApp"
Call Fnc_CloseApp
Case "Fnc_OpenApp"
Call Fnc_OpenApp
Case "Fnc_Login"
Call Fnc_Login
Case "Fnc_BookTicket"
Call Fnc_BookTicket()
End Select
End If
Next

'ObjExcel.ActiveWorkbook.Save
ObjExcel.ActiveWorkbook.Close
ObjExcel.Application.Quit
'Release the objects
Set ObjSheet = Nothing
Set ObjExcel = Nothing

5. Flight_Reservation.tsr (A Shared Object Repository which contains all the
test objects of application under test)
The Shared Object repository needs to be associated with the Action (DriverScript)
Steps to associate shared Object Repository:

1. Resources – > Associate Repositories...
2. In the 'Associate Repositories' window click on 'Add Repository' icon (+) to
browse the shared Object Repository
3. Select the shared Object Repository and associate with the available action.


6. Generic.qfl (A Function library which contains general functions)
'Function to genearte Random characters
Function Fnc_GenerateRandomCharacters(num)
str = "abcdefghijklmnopqrstuvwxyz"
For i = 1 To num Step 1
Randomize
n = Int((Rnd*26)+1)
char = Mid(str,n,1)
vstr = vstr&char
Next
Fnc_GenerateRandomCharacters = vstr
End Function
'Function to generate numbers
Function Fnc_GenerateNumbers(num)
For i=1 to num Step 1
Randomize

n = Int((Rnd*10))
If n<9 Then
n = n+1
End If
v_int_num = v_int_num&n
Next
Fnc_GenerateNumbers = v_int_num
End Function
'Function to Close All Browsers
Function Fnc_CloseBrowsers()
Set v_ob_Browser = Description.Create
v_ob_Browser("micClass").Value = "Browser"
Set v_ob_Browser1 = Desktop.ChildObjects(v_ob_Browser)

If v_ob_Browser1.Count > 0 Then
For i = v_ob_Browser1.Count-1 To 0 Step -1
Browser("creationtime:="&i).Close
Next
End If
End Function
'Delete files one by one from a particular folder
Function Fnc_DeleteFiles(Folder_Path)
Set fso = CreateObject("Scripting.FileSystemObject")
Set get_Folder = fso.GetFolder(Folder_Path)
If get_Folder.Files.Count > 0 Then
For each f in get_Folder.Files
On Error Resume Next
f.delete True
If Err.Number <> 0 Then
Reporter.ReportEvent micFail,"Error Occured","Error
Description -- "&Err.Description

Comments

Popular posts from this blog

KeyWord Driven Framework Using UFT