功能說明:出現一個提示對話框,N秒后消失,比如說:提示等待一個窗口阿,有時候這個窗口沒了,我也不知道腳本運行到什么地方了,提示一下挺好,也方便其他的測試員修改,而且,也不影響無人值守的操作
例子:SQAMsgbox "test","title",5
Global iTime as Integer
Declare Function TimedDlgFunc(id As String, Action As Integer, Suppvalue As Long) As Integer
Declare Function SQAMsgBox(sMsgText as String, Optional vMsgCaption as Variant, Optional vTimeOut as Variant) as Integer
Function TimedDlgFunc(id As String, Action As Integer, Suppvalue As Long) As Integer
Static StartTime
Dim EndTime
Dim vTimeoutvalue as Variant
Select Case Action
Case 1 'Dialog box Initialization
StartTime = Timer
If StartTime + iTime >= 86400 Then
StartTime = 86400 - StartTime - iTime
End If
TimedDlgFunc = 1
Case 2 'Button pushed or any control changed (except typing in text or combo box)
Select Case Suppvalue
Case 1
DlgEnd -1
Case 2
DlgEnd 0
Case Else
TimedDlgFunc = 0
End Select
Case 3 'Change in text or combo box contents
TimedDlgFunc = 1
Case 4 'Change of control focus
TimedDlgFunc = 1
Case 5 'Idle state (return 0 to prevent this being continually called)
EndTime = Timer
If (EndTime - StartTime) >= iTime Then
DlgEnd -1
End If
vTimeoutvalue = Format(iTime - (EndTime - StartTime), "#.#")
DlgText DlgControlID("txtTimevalue"), CStr(vTimeoutvalue)
TimedDlgFunc = 1
End Select
End Function
Function SQAMsgBox(sMsgText as String, Optional vMsgCaption as Variant, Optional vTimeOut as Variant) as Integer
Dim Result as Integer
Dim TotalTime As Integer
Dim sCmdText as String
Dim sTimeoutText as String
Dim vvalue as Variant
If IsMissing(vMsgCaption) Then
vMsgCaption = "SQAMsgBox"
End If
If IsMissing(vTimeOut) Then
vTimeOut = 20 'seconds
End If
sTimeoutText = "Timeout: "
'-----
Begin Dialog dlgMsgBox 200, 80, vMsgCaption, .TimedDlgFunc
GroupBox 5, 2, 190, 40, "", .grpMsgTxt
Text 15, 11, 175, 25, sMsgText, .txtMsgText
Text 15, 47, 180, 20, sCmdText, .txtCmdText
'--------------
Button 20, 60, 40, 14, "&OK", .btnOK
Button 140, 60, 40, 14, "&Cancel", .btnCancel
Text 78, 63, 30, 10, sTimeoutText, .txtTimeText
Text 108, 63, 20, 10, vTimeout, .txtTimevalue
End Dialog
'-----
Dim TimedDlg As dlgMsgBox
iTime = CInt(vTimeOut)
Result = Dialog(TimedDlg)
If Result = 2 Then
SQAMsgBox = sqaFail
Else
SQAMsgBox = sqaPass
End If
End Function
關于Recognition
一共分為Recognition, ParentRecognition, FullRecognition
1. To find the recognition method of the currently active window:
Result=SQAGetProperty(".\","Recognition",value)
Returned value:
Type=Window;Name=frmMain
抓出來的是當前窗口的一些信息
2. To find the immediate parent of the tree view item Bach:
Result=SQAGetProperty("Name=treMain;\;ItemText=Bach","ParentRecognition",value)
Returned value:
Type=TreeView;Name=treMain
抓出來的是樹型結構的父結點的信息
3. To find the complete object path of the tree view item Bach, beginning with the desktop and ending with the target object itself:
Result=SQAGetProperty("Name=treMain;\;ItemText=Bach","FullRecognition",value)
Returned value:
Type=Window;Name=frmMain;\;Type=TreeView;Name=treMain;\;Type=TVItem;ItemText=Bach
抓出來的是樹型結構中指向該控件的全部路徑
Rational Robot中自動進行100次操作
Rational Robot中的SQA Basic與Basic語言極為類似,下面是一個for循環的例子,其中cstri()函數把整數轉換成字符串。
Sub Main
Dim Result As Integer
Dim i As Integer
……
'begin of for loop
for i=1 to 100 step 1
……
InputKeys cstr(i*3) '這個地方設置輸入值為I*3.
……
next
'end of for loop
……
End Sub
使用Rational Robot錄制自動測試GUI腳本,在點擊一個按鈕以后,出現的結果可能有多種,可能會出現一個含“確定”按鈕的對話框,也可能出現一個標題為”Title abcd”的窗體,可以使用SQAWaitForPropertyvalue方法來判斷出現的屬性,或者使用SQAWaitForObject來判斷出現何種窗體,下面是兩個對可能出現的屬性進行判斷的例子。
1).2秒內假若出現確定對話框,點擊確定按鈕,否則打印"確定按鈕未出現" :
'等待2秒直到確定按鈕出現.
Result = SQAWaitForPropertyvalue("Text=(O)確定", "Enabled",TRUE, 2000)
If Result <> sqaSuccess Then
print "確定按鈕未出現"
Else
PushButton Click, "Text=(O)確定"
End If
2).2秒內假若出現標題為"Title abcd" 的窗體,打印"出現標題為Title abcd的窗體" ,否則打印"未出現標題為Title abcd的窗體" :
'等待2秒直到標題為Title abcd的窗體出現.
Result = SQAWaitForPropertyvalue("Caption=Title abcd", "Enabled",TRUE, 2000)
If Result <> sqaSuccess Then
PushButton Click, "Text=(O)確定"
print "出現標題為Title abcd的窗體"
Else
print "未出現標題為Title abcd的窗體"
End If
說明:
1).Result是一個Integer型變量;
2).SQAWaitForPropertyvalue:顧名思義,指的是等待一個屬性被指定值之前暫停執行。SQAWaitForPropertyvalue("Text=(O)確定", "Enabled",TRUE, 2000)表示等待2秒直到確定按鈕出現,如果2秒內未出現,則返回sqlfalse,出現則返回sqlsuccess;
3).SQA Basic中<>表示不等于;
4).另外,可以用SQAWaitForObject來判斷出現出現的對象類型:
Result = SQAWaitForObject("Type=PushButton;Text=OK", 2000)
If Result = sqaSuccess Then
... ' add the rest of the actions/tests here
End If
識別控件
需要相應的enabler,你現在測試的程序是delphi開發的應用軟件,那么就要加載相應的delphi enabler!
extension manager里邊加入了delphi enabler,但是這個還是不能識別出delphi開發中用到的第三方控件或則其他控件!其實這里選擇只是個打開使用真正的delphi enabler的開關,真正的delphi其實是一個sqasrvr.pas的單元文件,這個單元文件是識別控件的核心。
ratitonal 2003里邊的test enabler安裝選項中包含delphi enabler,但是它需要你本機上安裝delphi,才會把delphi enabler安裝到你的機器上。否則不會出現。
假如安裝成功后,會在開始菜單中rational菜單下,rational test菜單下出現個delphi enabler(具體什么名字忘記了)的菜單項,通過它可以調用一個執行文件。
執行文件的功能就是把sqasrvr.pas自動放到工程文件的頭。
delphi 工程文件只有加載了這個delphi enabler(核心 sqasrvr.pas)才會讓robot識別,當然前提是你的extension manager中delphi選擇了。
Robot手工編寫GUI腳本如何獲取對象識別方法和屬性
文章來源于領測軟件測試網 http://www.kjueaiud.com/