Keyword Driven Framework in UFT

Keyword Driven Framework in UFT

I) Steps for Keyword Driven Framework using UFT

a) Create folder structure to store Automation Resources

b) Create Automation Resources and store

c) Create Organizer spread sheet
(It provides instructions to Driver script)

d) Generate Driver script (UFT Test)
(All resources can be associated with the Driver, it executes tests one by one based on Organizer instructions  and export test result.)

e) Generate Initialization script (AOM script)
(It launches UFT tool, calls driver script and closes UFT Tool)
II) Create Functions
''Function Name: Login

'Author: abcd

'Date of Creation: 08th November 2014

'Date of modification: NA

'Input: Agent name and Password

'Output / Outcome:Flight Reservation window

'Purpose: Login to Flight Reservation Application
Function Login(Agent, Password)
SystemUtil.Run "C:\Program Files\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set Agent
Dialog("Login").WinEdit("Password:").Set Password

If Window("Flight Reservation").Exist(12) Then
    Login = "Login Successful - Passed"
    Login = "Login Unsuccessful - Failed"
End If
'Msgbox Login
End Function
'    Close Application
Function Close_App()
If Window("Flight Reservation").Exist(3) Then
    Window("Flight Reservation").Close
End If
Wait 2
If  Not Window("Flight Reservation").Exist(3) Then
    Close_App = "Application Not Exists - Passed"
    Close_App = "Application Exists -Failed"
End If
'Msgbox Close_App
End Function
'    Open Order
Function OpenOrder(ord)
Window("Flight Reservation").WinButton("Button_2").Click
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ord
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
OrderNo = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")

If OrderNo <> "" Then
If ord = Cint(OrderNo) Then
    OpenOrder = ord & " Order Opened- Passed"
End If
If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").exist(3)
Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("OK").Click
Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click
End If
    OpenOrder = ord & " Order Not Opened- Failed"
End If
'msgbox OpenOrder
End Function
'    Update Order
Function UpdateOrder(Tickets)
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "1"
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Tickets:").SetSelection 0,1
Window("Flight Reservation").WinEdit("Tickets:").Set Tickets
Window("Flight Reservation").WinButton("Update Order").Click
Wait 9
Message = Window("Flight Reservation").ActiveX("Threed Panel Control").GetROProperty("text")
If Message = "Update Done..." Then
    UpdateOrder = "Order Updated- Passed"
If Window("Flight Reservation").Dialog("Flight Reservations").Exist(3) Then
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("OK").Click
Window("Flight Reservation").WinButton("Button_2").Click
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("No").Click
End If
UpdateOrder = "Order Not Updated- Passed"
End If
'Msgbox UpdateOrder
End Function
III) Create Driver Script

Dim MRowCount, i, ModuleExe, ModuleId, TCRowCount, j, ModuleId2, TestCaseExe, TestCaseId
Dim TSRowCount, k, TestCaseId2, Keyword
'Add new sheet to Run-time Data Table to import instructions from the Organizer
DataTable.AddSheet "Module"
DataTable.AddSheet "TestCase"
DataTable.AddSheet "TestStep"

'Import data from an external file.
DataTable.ImportSheet "C:\Users\G C Reddy\Desktop\Keyword Driven\Organizer\Organizer.xls", 1, 3
DataTable.ImportSheet "C:\Users\G C Reddy\Desktop\Keyword Driven\Organizer\Organizer.xls", 2, 4
DataTable.ImportSheet "C:\Users\G C Reddy\Desktop\Keyword Driven\Organizer\Organizer.xls", 3, 5

'Read executable Module ids from Module sheet
MRowCount= DataTable.GetSheet(3).GetRowCount

For i = 1 To MRowCount Step 1
    ModuleExe = DataTable(3, 3)
    If UCase(ModuleExe) = "Y" Then
        ModuleId = DataTable(1, 3)
        'Msgbox ModuleId
'Read executable Test Case id's under executable modules from Test Case sheet
TCRowCount = DataTable.GetSheet(4).GetRowCount
For j = 1 To TCRowCount Step 1
    ModuleId2 = DataTable(4, 4)
    TestCaseExe = DataTable(3, 4)
    If UCase(TestCaseExe) = "Y" And  ModuleId = ModuleId2 Then
        TestCaseId = DataTable(1, 4)
        'Msgbox TestCaseId
'Read Keywords for all executable steps from TestStep sheet
TSRowCount = DataTable.GetSheet(5).GetRowCount
For k = 1 To TSRowCount Step 1
    TestCaseId2 = DataTable(6, 5)
    If TestCaseId = TestCaseId2 Then
        Keyword = DataTable(4, 5)
        'Msgbox Keyword
        Select Case Keyword
            Case "ln"
            DataTable(7, 5) = Login("abcd", "mercury")
            Case "ca"
            DataTable(7, 5) = Close_App()
            Case "oo"
            DataTable(7, 5) =OpenOrder(4)
            Case "uo"
            DataTable(7, 5) =UpdateOrder(2)
           End Select
        End If
    End If
End If
DataTable.ExportSheet "C:\Users\G C Reddy\Desktop\Keyword Driven\TestResults\Result1.xls", 5
IV) Create Initialization Script

Dim objQTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Visible = True ' To view the UFT tool while execution

objQTP.Launch 'To launch UFT Tool
objQTP.Open "C:\Users\G C Reddy\Desktop\Keyword Driven\Drivers\Driver"

Set objQTP = Nothing


Post a Comment