robot函數實例講解(一)

發表于:2008-10-23來源:作者:點擊數: 標簽:robotRobot講解實例函數
功能說明:出現一個提示對話框,N秒后消失,比如說:提示等待一個窗口阿,有時候這個窗口沒了,我也不知道腳本運行到什么地方了,提示一下挺好,也方便 其他 的 測試 員修改,而且,也不影響無人值守的操作 例子:SQAMsgbox "test","title",5 Global iTime a

功能說明:出現一個提示對話框,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 <> sqaSuclearcase/" target="_blank" >ccess 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腳本如何獲取對象識別方法和屬性

以計算器為例,下面的腳本是鍵盤輸入“1+1=”,然后關閉計算器。
Sub Main
    Dim Result As Integer

    StartApplication "C:\WINNT\system32\calc.exe"
   
    Window SetContext, "Caption=計算器", ""
    InputKeys "1{+}1{ENTER}"
    Window CloseWin, "", ""

End Sub
   
    Robot提供了獲取對象識別方法和屬性的利器――Inspector。通過Robot tools-Inspector..打開?,F在使用SQAGetProperty命令獲取1+1的結果值,并通過msgbox顯示該值。
    鼠標左鍵按住Inspectot工具欄上的“Select Objcet”按鈕,然后選擇計算器的結果放開鼠標左鍵。Inspectot中顯示出對象的識別方法,鼠標左鍵點擊工具欄上的“Copy recognition String”按鈕拷貝識別方法,屬性值通過選擇Inspector左下角窗口中的Text屬性,然后鼠標左鍵點擊工具欄上的“Copy”按鈕拷貝屬性。修改后的腳本如下:
Sub Main
    Dim Result As Integer
    Dim sum as Variant

    StartApplication "C:\WINNT\system32\calc.exe"
   
    Window SetContext, "Caption=計算器", ""
    InputKeys "1{+}1{ENTER}"
   
    Result = SQAGetProperty ("Type=Label;ObjectIndex=1", "Text", sum)
    msgbox sum
   
    Window CloseWin, "", ""

End Sub

   

原文轉自:http://www.anti-gravitydesign.com

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