透析QTP自動化測試框架SAFFRON(4)

發表于:2014-11-25來源:uml.org.cn作者:陳能技點擊數: 標簽:
在SAFFRON中,可以使用EnterTextIn函數來給輸入框(WebEdit對象)輸入字符串。EnterTextIn函數的定義如下所示: Enters text into an edit field objname - name of the control

在SAFFRON中,可以使用EnterTextIn函數來給輸入框(WebEdit對象)輸入字符串。EnterTextIn函數的定義如下所示:
' Enters text into an edit field
' objname - name of the control -- use Object Spy if you don't know what it is
' text - the text to enter into the control
Public Function EnterTextIn (objname, text)
localDesc = ""
rval = true
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If

AutoSync()

localDesc = localdesc & GenerateObjectDescription("WebEdit", "name:=" & objname)
Execute localDesc & "Set (" & Quote(text) & ")"
Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " & Quote(objname)
EnterTextIn = rval
End Function

例如,如果我們要在如圖所示的登錄界面中輸入用戶名和密碼,則可以使用SAFFRON的EnterTextIn函數來實現。

測試腳本可以這樣編寫:
' 輸入用戶名
EnterTextIn "username","chennengji"
' 輸入密碼
EnterTextIn "password","123"

4.9 讀取文本框的字符串

在SAFFRON中,可以使用EnterTextIn函數來給輸入框(WebEdit對象)輸入字符串。對應的有一個名為GetTextFrom的函數,用于讀取輸入框和文本列表的字符串,GetTextFrom的定義如下所示:
' Obtains text from a control
' objtype - is the type of control the get the text from
' objname - is the name of the control -- use Object Spy if you don't know the name
' returns - the text of the control
Public Function GetTextFrom (objtype, objname)
text = ""
localDesc = ""
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If

AutoSync()

Select Case objtype
Case "WebEdit"
Execute "text = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
Case "WebList"
Execute "text = " & localDesc & GenerateObjectDescription("WebList", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
End Select
Report micPass, "Capture Text", "Text: " & Quote(text) & " was captured from the control " & Quote(objname)
GetTextFrom = text
End Function

假設我們需要讀取如圖所示的界面中的“Departure City”和“Arrival City”這兩個文本列表(WebList對象)中的字符串,則可以使用GetTextFrom函數。

測試腳本可以這樣編寫:
' 獲取航班起始城市
DepartureCity = GetTextFrom( "WebList","depart")
' 獲取航班終點城市
ArrivalCity = GetTextFrom( "WebList","arrive")

當然,也可以使用相同的函數來讀取文本框(WebEdit對象)的字符串,例如下面的腳本讀取“NO. of Passengers”對應的文本框中的字符串:
' 獲取乘客數量
PassengerNumber = GetTextFrom( "WebEdit","numPassengers")

4.10選擇列表中的一項

在SAFFRON中,可以使用SelectFromList函數從下拉框列表(WebList對象)中選擇指定的一項。SelectFromList的定義如下所示:
' Selects a specific value from a listbox, or combobox
' objname - name of the control -- use Object Spy if you don't know the name property
' text - the item in the combobox to select
Public Function SelectFromList (objname, text)
localDesc = ""
rv = ""
rval = false
If thirdlevel <> "" Then
localDesc = GenerateDescription(level(2))
Else
localDesc = GenerateDescription(level(1))
End If

AutoSync()

localDesc = localdesc & GenerateObjectDescription("WebList", "name:=" & objname)

Execute "cnt = " & localDesc & "GetROProperty(" & Quote("items count") & ")"
For i = 1 to cnt
Execute "rv = " & localDesc & "GetItem (" & i & ")"
If rv = text Then
rval = true
End If
Next

If rval Then
Execute localDesc & "Select " & Quote(text)
End If
If rval Then
Report micPass, "WebList Selection", "The WebList item " & Quote(text) & " was selected."
Else
Report micFail, "WebList Selection", "The WebList item " & Quote(text) & " was NOT found."
End If

SelectFromList = rval
End Function

假設我們需要從如圖所示的界面中的“Departure City”的下拉框中選擇其中一項,則可使用SelectFromList函數來實現。

測試腳本可以這樣寫:
' 選擇航班起始城市為"San Francisco"
SelectFromList "depart","San Francisco"

4.11 關閉瀏覽器

原文轉自:http://www.uml.org.cn/Test/200810108.asp

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97