功能说明:出现一个提示对话框,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脚本如何获取对象识别方法和属性
以计算器为例,下面的脚本是键盘输入“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..打开。现在使用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
文章来源于领测软件测试网 https://www.ltesting.net/