I'm trying to do a keyword driven framework and the Function where I call
the different actions has different Case depending on the action I want to
perform. What I have to do to eliminate the Execute Command?
The control_object variable has the the hierarchy similar or equal to
(Browser(arrParentProp(0)).Page(arrParentProp(1)).Frame(arrParentProp(2)).WebButton(arrParentProp(3))
Why QTP is not only accepting ->->-> control_object.click
here is part of my code;
If you want to see all the function library see the attachment please.
Code:
Case "Click_Link"
sExec = control_object &
".click"
Execute (sExec)
Case
"Click_WebButton"
sExec = control_object & ".click"
Execute (sExec)
'Same thing happen with every case, for example *****
Case "Run"
sExec = "systemutil.Run" & sDataValue
Execute (sExec)
Browser("Main").Page("Main").Sync
Browser("Main").Page("Main").WebList("Environment").Select
"System Integration (UAT)"
--
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en
---
You received this message because you are subscribed to the Google Groups "QTP
- HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
Option Explicit
'Variable Initialization and Declaration
Dim sExcelLocation
'Path
of Excel Sheet location
Dim sParent, sParentProp, arrParent, arrParentProp, sControl,
sControlProp, arrControlProp, sAction, sDataValue, iRow, iR
Dim obj_hierarchy, control_object, sExec
Dim Q
' Variable defined to insert double quotes to variables
name. ex. ""Browser("& Q & (arrParentProp(0)) & Q & ").Page(" & Q
&(arrParentProp(1)) & Q &")."
Dim x, y, z
Q = """"
sExcelLocation = "C:\KDF2\Flow
Sheets\MercuryFlightReservation.xls"
'========================================
' Function Name - fnExecuteTestCase
' Purpose - This is just a wrapper function that calls
fnReadExcel function
'========================================
Function fnExecuteTestCase(Benefits_Test01)
fnReadExcel(Benefits_Test01)
End Function
'============= End Function ===============
'========================================
' Function Name - fnReadExcel
' Purpose - This function loads the excel sheet into QTP
data table and stores the cell values in Global Variables
'========================================
Function fnReadExcel(sSheetName)
'Add the Data Sheet into QTP Data Table
DataTable.AddSheet("dtSheet")
'Import the Excel Sheet into QTP Data Table
DataTable.ImportSheet sExcelLocation, sSheetName,
"dtSheet"
'Loop through all the rows in the Data Sheet
iRow = DataTable.GetSheet("dtSheet").GetRowCount
For iR = 1 to iRow
'Set the Current Row in the Data Sheet according to the loop
counter
DataTable.SetCurrentRow iR
'Capture all the cell values in different variables
sParent = DataTable("Parent", "dtSheet")
sParentProp = DataTable("PProperty", "dtSheet")
sControl = DataTable("Control", "dtSheet")
sControlProp = DataTable("CProperty", "dtSheet")
sAction = DataTable("Action", "dtSheet")
sDataValue = DataTable("Data", "dtSheet")
y = DataTable("Column_Text", "dtSheet")
z =
DataTable("Column_Radio_or_ChkBox","dtSheet")
'Call the function that will convert the excel data into QTP
readable format
If sParent = "End" Then
Exit For
ElseIf sParent <> "" Then
fnIdentifyParentHierarchy()
Else
'The action is independent of the all the controls (refer NOTE
2 from the article)
fnAction()
End If
Next
End Function
'============= End Function ===============
'========================================
' Function Name - fnIdentifyParentHierarchy
' Purpose - This function converts the values in cells A
and B into QTP readable format
'========================================
Function fnIdentifyParentHierarchy()
'Split Parent Property so that multiple objects can be resolved
arrParentProp = Split(sParentProp, ",")
'Resolve the hierarchy of all objects that are parent to the
actual control
Select Case sParent
Case "Browser"
Set obj_hierarchy = "Browser(" & Q &
(arrParentProp(0)) & Q & ")."
Case "Browser,Dialog"
Set obj_hierarchy = "Browser("& Q &
(arrParentProp(0)) & Q & ").Dialog(" & Q &(arrParentProp(1)) & Q &")."
Case "Browser,Page"
Set obj_hierarchy = "Browser("& Q &
(arrParentProp(0)) & Q & ").Page(" & Q &(arrParentProp(1)) & Q &")."
Case "Browser,Page,Frame"
Set obj_hierarchy = "Browser("& Q &
(arrParentProp(0)) & Q & ").Page(" & Q &(arrParentProp(1)) & Q & ").Frame(" & Q
& (arrParentProp(2)) & Q & ")."
'msgbox obj_hierarchy
Case "Browser,Window,Page,Frame"
Set obj_hierarchy = "Browser("& Q &
(arrParentProp(0)) & Q & ").Window("& Q & (arrParentProp(1))& Q & ").Page(" & Q
& (arrParentProp(2)) & Q & ").Frame("& Q & (arrParentProp(3)) & Q & ")."
Case "Browser,Page,Frame,WebTable"
Set obj_hierarchy = "Browser("& Q &
(arrParentProp(0)) & Q & ").Page("& Q & (arrParentProp(1))& Q & ").Frame(" & Q
& (arrParentProp(2)) & Q & ").WebTable("& Q & (arrParentProp(3)) & Q & ")."
'msgbox "The obj_hierarchy is = " & obj_hierarchy
Case "Browser,Window,Dialog"
Set obj_hierarchy = "Browser("& Q &
(arrParentProp(0)) & Q & ").Window(" & Q &(arrParentProp(1)) & Q & ").Dialog("
& Q & (arrParentProp(2)) & Q & ")."
'Set obj_hierarchy =
Browser(arrParentProp(0)).Window(arrParentProp(1)).Dialog(arrParentProp(2))
End Select
'Call the function that will resolve the Control Object
fnIdentifyControl()
End Function
'============= End Function ===============
'========================================
' Function Name - fnIdentifyControl
' Purpose - This function converts the values in cells C
and D into QTP readable format and then combines values from Cells A, B, C and
D to come up with a single object
'========================================
Function fnIdentifyControl()
If sControl <> "" Then
arrControlProp = sControlProp
'Resolve the Control object to obtain the complete heirarchy on
which the action can be performed
Set child_object = Description.Create()
child_object("micclass").value = sControl
child_object(arrControlProp(0)).value =
arrControlProp(1)
'Create the object on which the action will be
performed
Set control_object =
obj_hierarchy.Childobjects(child_object)
Else
'Control Object is the parent hierarchy on which the action
will be performed (refer NOTE 1 from the article)
Set control_object = obj_hierarchy
End If
'Call the function that will perform the necessary action on
the object
fnAction()
End Function
'============= End Function ===============
'========================================
' Function Name - fnAction
' Purpose - This function performs action on the object
based upon the defined keyword
'========================================
Function fnAction()
Dim rowIndex, rowCheck, Get_Data
Dim Allitems, WaitValue, Actual
x = 0
y = 0
z = 0
'x = usually is the number of row that match the text(y) we
are looking for
'y = Column containing the text we are looking for
'z = Number of WebRadioGroup Column or WebCheckBox
'Perform Action on the control_object based upon the keyword
defined in the excel sheet
Select Case sAction
Case "TypeText_WebEdit"
sExec = control_object & ".Set " & Q & sDataValue & Q
Execute (sExec)
Case "TypeText_Dialog"
sExec = control_object & ".Set " & Q &
sDataValue & Q
Execute (sExec)
Case "Select_RadioButton" 'Radio that act
individual
rowIndex =
Browser(arrParentProp(0)).Page(arrParentProp(1)).Frame(arrParentProp(2)).WebTable(arrParentProp(3)).GetRowWithCellText(sDataValue,z,1)
x = rowIndex
set sExec =
Browser(arrParentProp(0)).Page(arrParentProp(1)).Frame(arrParentProp(2)).WebTable(arrParentProp(3)).ChildItem(x,z,"WebRadioGroup",0)
sExec.click
Case "Set_WebCheckBox"
sExec = control_object & ".Set " & Q &
sDataValue & Q
Execute (sExec)
Case "Select_WebList"
sExec = control_object & ".Select " & Q &
sDataValue & Q
Execute (sExec)
Case "Select_WebRadioGroup" 'Radio that act
as a Group
'WebTable and WebRadioGroup should have the same name in the OR.
x =
Browser(arrParentProp(0)).Page(arrParentProp(1)).Frame(arrParentProp(2)).WebTable(arrParentProp(3)).GetRowWithCellText(sDataValue,1)
x = x - 1
Browser(arrParentProp(0)).Page(arrParentProp(1)).Frame(arrParentProp(2)).WebRadioGroup(arrParentProp(3)).Select
"#" & x
Case "Click_WebElement"
'
sExec = control_object & ".click"
Execute (sExec)
Case "Click_Dialog"
sExec = control_object & ".click"
Execute (sExec)
Case "Click_Image"
sExec = control_object & ".click"
Execute (sExec)
Case "Click_Link"
sExec = control_object & ".click"
Execute (sExec)
Case "Click_WebButton"
sExec = control_object & ".click"
Execute (sExec)
Case "Wait"
sDataValue = cInt(sDataValue)
Wait (sDataValue)
Case "Set_ON_Table_WebCheckBox"
rowIndex =
Browser(arrParentProp(0)).Page(arrParentProp(1)).Frame(arrParentProp(2)).WebTable(arrParentProp(3)).GetRowWithCellText(sDataValue,y,1)
x = rowIndex
rowCheck =
trim(Browser(arrParentProp(0)).Page(arrParentProp(1)).Frame(arrParentProp(2)).WebTable(arrParentProp(3)).GetCellData(x,y))
If rowCheck = trim(sDataValue) Then
Browser (arrParentProp(0)).Page
(arrParentProp(1)).Frame (arrParentProp(2)).WebTable
(arrParentProp(3)).ChildItem(x ,1, "WebCheckBox", 0).Set "ON"
End if
' If Browser
(arrParentProp(0)).Page (arrParentProp(1)).Frame (arrParentProp(2)).WebTable
(arrParentProp(3)).ColumnCount(x) = 1 Then
' y = 1
' End If
'
' Do
' Get_Data = (Browser
(arrParentProp(0)).Page (arrParentProp(1)).Frame (arrParentProp(2)).WebTable
(arrParentProp(3)).GetCellData(x,y)) 'Row and Column respectively
'
' If instr(1, Get_Data,
sDataValue) > 0 Then
' Get_Property =
(Browser (arrParentProp(0)).Page (arrParentProp(1)).Frame
(arrParentProp(2)).WebTable (arrParentProp(3)).GetROProperty("outerhtml"))
' Get_Split =
split(Get_Property, "</TR>")
' z = x - 1
' Do
'
' If
instr(Get_Split(z),trim(sDataValue)) > 0 Then
'
Browser (arrParentProp(0)).Page (arrParentProp(1)).Frame
(arrParentProp(2)).WebTable (arrParentProp(3)).ChildItem(x ,1, "WebCheckBox",
0).Set "ON"
'
If Browser (arrParentProp(0)).Page (arrParentProp(1)).Frame
(arrParentProp(2)).WebTable (arrParentProp(3)).ChildItem(x ,1, "WebCheckBox",
0).GetROProperty("checked")Then
'
x = Row_Count
'
Else
'
x = x
'
End If
'
Exit Do
' Else
'
z = z
' End If
'
' Loop until z =
ubound(Get_Split) + 1
'
' End if
' x = x + 1
' Loop until instr(Get_Data,
"ERROR") = 1
'
' If
instr(Get_Split(z),trim(sDataValue)) > 0 Then
' End If
'
Case "Activate"
sExec = control_object & ".Activate"
Execute (sExec)
Case "WindowClose"
sExec = control_object & ".Close"
Execute (sExec)
'===============================================================================
'Purpose: PATH OF THE ENVIRONMENT (CAN BE UAT OR PRODUCTION)
'===============================================================================
Case "Run"
sExec = "systemutil.Run" & sDataValue
Execute (sExec)
Browser("Main").Page("Main").Sync
Browser("Main").Page("Main").WebList("Environment").Select "System Integration
(UAT)"
Case "SendKeys"
'This function uses SendKeys method to select value from the
Menu
Set WshShell = CreateObject("WScript.Shell")
Select Case sDataValue
Case "Alt F+N"
WshShell.SendKeys "%(fn)"
Case "Alt F+O"
WshShell.SendKeys "%(fo)"
End Select
Set WshShell = Nothing
End Select
End Function
'============= End Function ===============