主要的几个文件:
-
Configuration.xml:< Parameters >
< Login >
< txtLogin > Login </ txtLogin >
< userName > Agent Name: </ userName >
< password > Password: </ password >
< btnOk > OK </ btnOk >
< LoginExcep > Flight Reservations </ LoginExcep >
< mainForm > Flight Reservation </ mainForm >
</ Login >
</ Parameters >
-
clsParameters.vbs:Class Parameters
Private xmlObj, root
Private sub Class_Initialize()
Set xmlObj = XMLUtil.CreateXML()
xmlObj.LoadFile( " Configuration.xml " )
End Sub
Private Sub Class_Terminate()
Set xmlObj = Null
End Sub
Public Function getValue(thePath)
getValue = xmlObj.ChildElementsByPath(thePath).Item( 1 ).Value
End Function
Public Sub setValue(thePath, theValue)
element = xmlObj.ChildElementsByPath(thePath).Item( 1 )
element.setValue(theValue)
xmlObj.SaveFile( " Configuration.xml " )
End Sub
Public Function getAllParameters(thePath)
Dim element, coll
Set coll = xmlObj.ChildElementsByPath(thePath)
xcount = coll.Item( 1 ).ChildElements.Count()
ReDim arrParameters( CInt (xcount))
For I = 1 to xcount
Set element = coll.Item( 1 ).ChildElements.Item(I)
arrParameters(I) = element.ElementName + " : " + element.Value
Next
getAllParameters = arrParameters
End Function
End Class
Function SplitParameter(paras, element)
Dim arrItem, result, x
For Each x In paras
arrItem = Split (x, " : " , 2 , 1 )
If UBound (arrItem) > 0 Then
If arrItem( 0 ) = element Then
result = arrItem
Exit For
End If
End If
Next
SplitParameter = result
End Function
-
QTP的Action: actionLogin, 设置Action Call Property: Data table iterations为Run on all rows:ExecuteFile " clsParameters.vbs "
Dim testId, allParameters, arrParameters
Dim tagMainForm, tagLogin, tagUserName, tagPassword, tagBtnOk, tagBoxException, tagErrMessage
Set allParameters = New Parameters
arrParameters = allParameters.getAllParameters( " /Parameters/Login " )
tagMainForm = " text:= " + SplitParameter(arrParameters, " mainForm " )( 1 )
tagLogin = " text:= " + SplitParameter(arrParameters, " txtLogin " )( 1 )
tagUserName = " attached text:= " + SplitParameter(arrParameters, " userName " )( 1 )
tagPassword = " attached text:= " + SplitParameter(arrParameters, " password " )( 1 )
tagBtnOk = " text:= " + SplitParameter(arrParameters, " btnOk " )( 1 )
tagBoxException = " text:= " + SplitParameter(arrParameters, " LoginExcep " )( 1 )
tagErrMessage = " window id:=65535 "
If Window(tagMainForm).Exist Then
Window(tagMainForm).Close
End If
If not Dialog(tagLogin).Exist Then
SystemUtil.Run " flight4a.exe " , "" , " C:Program FilesMercury InteractiveQuickTest Professionalsamples lightapp " , " open "
End If
With Dialog(tagLogin)
.Activate
.Check CheckPoint( " Login " )
.WinEdit(tagUserName).Set DataTable( " UserName_text " , dtLocalSheet)
.WinEdit(tagPassword).Set DataTable( " Password_Text " , dtLocalSheet)
.WinButton(tagBtnOk).Click
If .Dialog(tagBoxException).Exist( 3 ) Then
With .Dialog(tagBoxException)
.Static(tagErrMessage).Check CheckPoint( " ErrMessage " )
.WinButton(tagBtnOk).Click
End With
ElseIf Window(tagMainForm).Exist( 5 ) Then
With Window(tagMainForm)
.Activate
.Check CheckPoint( " Flight Reservation " )
End with
End If
End With
-
QTP中的DataTable:
DlgException_Static_text UserName_text Password_text Please enter agent name Agent name must be at least 4 characters long. aa Please enter password aaaa Password must be at least 4 characters long aaaa aa Incorrect password. Please try again aaaa aaaa mercury mercury
结束。