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
Dim TimedDlg As dlgMsgBox
iTime = CInt(vTimeOut)
Result = Dialog(TimedDlg)
If Result = 2 Then
SQAMsgBox = sqaFail
Else
SQAMsgBox = sqaPass
End If
End Function
*******************************************************************作者: sincky 时间: 2005-11-29 22:20
关于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
抓出来的是树型结构中指向该控件的全部路径作者: sincky 时间: 2005-11-29 22:21
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作者: sincky 时间: 2005-11-29 22:21
使用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
4).另外,可以用SQAWaitForObject来判断出现出现的对象类型:
Result = SQAWaitForObject("Type=PushButton;Text=OK", 2000)
If Result = sqaSuccess Then
... ' add the rest of the actions/tests here
End If作者: sincky 时间: 2005-11-29 22:21
识别控件
需要相应的enabler,你现在测试的程序是delphi开发的应用软件,那么就要加载相应的delphi enabler!
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
Rational test早期版本没有提供菜单选项来设置sqabasic路径 – 参阅sqa common directory片断
指导使用头文件和库文件
推荐下边使用库文件方法:
a) 自定义函数或者过程应该使用有同样文件名字的头文件(.sbh)和库文件(.sbl),比如DataFunctions.sbh和DataFunctions.sbl。这个过程和函数在头文件中定义(指定声明头文件)和在库文件中定义。看下边的例子
b) 分离头文件(参阅常量头文件)用于包含常量,变量和用户定义类型用于脚本或者库文件调用。头文件用同样的文件名字后边附加_x或则_C(附加是早期命名规定)。注意包含常量和变量的头文件必须加入到声明头文件和库文件之前。(DataFunctions.sbh和DataFunctions.sbl),比如’include “DateFunctions_c.sbh”。这样做很容易维护。
c) 通过分类或者程序把相关的函数放在同一个库里,例如,把所有日期相关的函数放到DataFunctions.sbh/sbl,或者把所有的函数加入为特定程序开发的函数库中(比如AppName.SBH/SBL)
例子:
Open “c:\test.dat" For Output As 1
Open “c:\test.dat" For Output As 1
这两句代码在c盘所在目录下创建了一个名为test.dat的文本文件,分配文件号为1.
Open “c:\test.dat"??For Input As [#]filenumber 这条语句是从文本文件中读取数据.
Open App.Path + "\test.dat" For Append As [#]filenumber?? 这条语句则是向文本文件中添加数据
随机文件的操作:
操作随机文件之前,首先必须定义用于保存数据项的记录类型.该记录是用户自定义数据类型,他们是随机文件中存储数据的基本结构.例如:
Type Student
No As Integer
Name As String * 20
age As Integer
End Type
Dim Stud As Student ‘定义一个可以存放学生材料的变量
随机文件中,所有的数据都将保存到若干个结构为Student类型的记录中, 而从随机文件中读出的数据则可以存放到变量Stud中.之后我们就可以打开并读写文件了.
随机文件的操作语法格式:
Open filename For Random as [#]filenumber Len = Reclength
说明:
(1)参数filename 和filenumber 分别表示文件名或文件号.
(2)关键字Random 表示打开的是随机文件
(3)Len子句用于设置记录长度,长度由参数Reclength指定.Reclength的值必须大于0,而且必须与定义的记录结构的长度一致.计算记录长度的方法是将记录结构中每个元素的长度相加.例如前面声明的Student的长度应该是2+20+2=24字节.
打开一个记录类型为Student 的随机文件的方法是:
Open "c:\Student.txt " For Random As #1 Len = 25
这里还有一种文件操作方式二进制文件,下边是他的语法格式:
Open pathname For Binary As [#]filenumber
说明:
(1) 参数filename 和filenumber 分别表示文件名或文件号.
(2)关键字Binary 表示打开的是二进制文件
(3)对于二进制文件,不能指定字节长度.每个打开的二进制文件都有一个自己的指针,文件指针是一个数字值,指向下一次读写操作的文件中的位置.二进制文件中的每个”位置”对应一个数据字节,因此,有n个字节的文件,就有1到n个位置.
我们可以用Seek()函数返回当前的文件指针位置(即下一个要读写的字节 );用Loc()函数返回上一次读写的字节位置,除非用Seek语句移动了指针,Loc()返回值总比Seek()的小1.我们来看下面的例子:
Open “路径:\student.txt” for Binary as #1? ? 该语句用二进制的方式打开了student.txt文件.作者: sincky 时间: 2005-11-29 22:26
二)写文件
1、 顺序文件
写顺序文件我们可以用Write # 和Print #语句向一个已经打开的文件中写入数据.
下面是他们的格式和说明:
'$include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim excel as Object
dim book as Object
dim worksheet as Object
dim s_name as String
dim s_pass as String
dim count as Integer
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Initiliaze excel
on error resume next
Set excel = GetObject(,"excel.application")
if(excel Is Nothing) then
Set excel = CreateObject("excel.application")
if(excel Is Nothing) then
MsgBox "Couldn't find Excel!"
Exit Sub
End if
End if
This example opens the data source named "SblTest," gets the names in the ODBC data sources, and closes the connection.
Sub main
' Declarations
'
Dim outputStr As String
Dim connection As Long
Dim prompt As Integer
Dim datasources(1 To 50) As Variant
Dim retcode As Variant
Dim action1 as Integer
Dim qualifier as String
prompt = 5
' Open the datasource "SblTest"
connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)
action1 = 1 ' Get the names of the ODBC datasources
retcode = SQLGetSchema(connection:=connection,action:=1, qualifier:=qualifier, ref:=datasources())
' Close the datasource connection
retcode = SQLClose(connection)
SQLError Example
This example forces an error to test SQLError function.
sub main
' Declarations
Dim connection As long
Dim prompt as integer
Dim retcode as long
Dim errors(1 To 3, 1 To 10) as Variant
Dim outputStr as String
' Open the datasource
connection = SQLOpen("DSN=SBLTESTW;UID=DBA;PWD=SQL",outputStr,prompt:=3)
' force an error to test SQLError select a nonexistent table
retcode = SQLExecQuery(connection:=connection,query:="select * from notable ")
' Retrieve the detailed error message information into the errors array
SQLError destination:=errors
retcode = SQLClose(connection)
end sub
SQLExecQuery Example
This example performs a query on the data source.
Sub main
' Declarations
'
Dim connection As Long
Dim destination(1 To 50, 1 To 125) As Variant
Dim retcode As long
Dim outputStr as String
Dim query as String
' open the connection
connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)
'
' Execute the query
query = "select * from customer"
retcode = SQLExecQuery(connection,query)
'
' retrieve the first 50 rows with the first 6 columns of each row into
' the array destination, omit row numbers and put column names in the
' first row of the array
'
retcode = SQLRetrieve(connection:=connection,destination:=destination,columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6,fetchFirst:=0)
' Get the next 50 rows of from the result set
retcode = SQLRetrieve(connection:=connection,destination:=destination,columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6)
' Close the connection
retcode = SQLClose(connection)
End Sub
SQLGetSchema Example
This example opens the data source named "SblTest," gets the names in the ODBC data sources, and closes the connection.
Sub main
' Declarations
'
Dim outputStr As String
Dim connection As Long
Dim prompt As Integer
Dim datasources(1 To 50) As Variant
Dim retcode As Variant
Dim action1 as Integer
Dim qualifier as String
prompt = 5
' Open the datasource "SblTest"
connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)
action1 = 1 ' Get the names of the ODBC datasources
retcode = SQLGetSchema(connection:=connection,action:=1, qualifier:=qualifier, ref:=datasources())
' Close the datasource connection
retcode = SQLClose(connection)
SQLOpen Example
This example opens the data source named "SblTest," gets the names in the ODBC data sources, and closes the connection.
Sub main
' Declarations
'
Dim outputStr As String
Dim connection As Long
Dim prompt As Integer
Dim datasources(1 To 50) As Variant
Dim retcode As Variant
Dim action1 as Integer
Dim qualifier as String
prompt = 5
' Open the datasource "SblTest"
connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)
action1 = 1 ' Get the names of the ODBC datasources
retcode = SQLGetSchema(connection:=connection,action:=1, qualifier:=qualifier, ref:=datasources())
' Close the datasource connection
retcode = SQLClose(connection)
SQLRequest Example
This example will open the datasource SBLTESTW and execute the query specified by query and return the results in destination
Sub main
' Declarations
'
Dim destination(1 To 50, 1 To 125) As Variant
Dim prompt As integer
Dim retcode as Variant
Dim query as String
Dim outputStr as String
' The following will open the datasource SBLTESTW and execute the query
' specified by query and return the results in destination
'
query = "select * from class"
retcode = SQLRequest("DSN=SBLTESTW;UID=DBA;PWD=SQL",query,outputStr,prompt,0,destination())
End Sub
SQLRetrieve Example
This example retrieves information from a data source.
Sub main
' Declarations
'
Dim connection As Long
Dim destination(1 To 50, 1 To 125) As Variant
Dim retcode As long
Dim query as String
Dim outputStr as String
connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)
'
' Execute the query
query = "select * from customer"
retcode = SQLExecQuery(connection,query)
' retrieve the first 50 rows with the first 6 columns of each row into
' the array destination, omit row numbers and put column names in the
' first row of the array
' Get the next 50 rows of from the result set
retcode = SQLRetrieve(connection:=connection,destination:=destination,columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6)
' Close the connection
retcode = SQLClose(connection)
End Sub
SQLRetrieveToFile Example
This example opens a connection to a data source and retrieves information to a file.
Sub main
' Declarations
'
Dim connection As Long
Dim destination As String
Dim retcode As Long
Dim query as String
Dim outputStr as String
Dim filename as String
Dim columnDelimiter as String
'
' Open the connection
connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)
' Execute the query
'
query = "select * from customer"
retcode = SQLExecQuery(connection,query)
' Place the results of the previous query in the file named by
' filename and put the column names in the file as the first row.
' The field delimiter is %
'
filename = "c:\myfile.txt"
columnDelimiter = "%"
retcode = SQLRetrieveToFile(connection:=connection,destination:=filename, columnNames:=1,columnDelimiter:=columnDelimiter)
您好!我按照你说的那个方法试了sqawaitforpropertyvalue(caption="Flight Reservations","enabled",true,2000)这个函数,但是总是提示我们1016,意思是在指定的时间内对像没有出现,可我的flight reservations窗体已经出现了,这是什么?作者: qi_cy 时间: 2006-10-25 21:28
辛苦啦 呵呵作者: haship 时间: 2006-11-2 20:40
谢谢分享!
顶,顶,顶……作者: ypeony 时间: 2006-11-13 16:24
谢谢啊,非常感谢!作者: zamaz 时间: 2007-1-31 15:05
不错,谢谢楼主分享!作者: tula 时间: 2007-6-16 14:53 标题: Please tell me where can I download IBM Rational Robot setup ? Please tell me where can I download IBM Rational Robot setup ? Thanks作者: handle 时间: 2007-7-27 09:55
顶一下,牛X了作者: xg_angell 时间: 2007-8-13 17:35 标题: 哪位有Crystal Report 8.5 QQ:274744797作者: huxijie 时间: 2007-8-20 11:00 标题: 回复 #1 sincky 的帖子 你好,您有robot的安装包么,我是刚学习测试的作者: lichenglin0801 时间: 2007-9-5 15:49
介绍的很详细,真是太好了作者: liujihui226 时间: 2007-9-14 09:45
辛苦了,写得很详细.作者: Iamwula 时间: 2007-9-14 19:25
辛苦啦,
呵呵,
非常感谢作者: chenzhgz 时间: 2007-9-19 13:29
真是好东西啊,牛人啦作者: youqi 时间: 2007-9-24 23:14 标题: 好贴 受益匪浅sdlkfj2作者: 026300 时间: 2007-9-29 09:57
基础知识普及型的好贴作者: zhaoevev 时间: 2007-10-1 10:03
非常需要,刚开始自动化测试作者: james.zhong 时间: 2007-10-29 12:47
绝对支持!!沙发~~~~~太牛了!慢慢消化中。。。。作者: AJMIAO 时间: 2007-12-20 16:28
好贴留名。学习。作者: arlenexhl 时间: 2008-5-21 14:41
辛苦了!谢谢! 有图片就更好了作者: guojunlin 时间: 2008-6-20 09:39
刚开始学习收藏一下作者: witt 时间: 2008-7-7 15:54
好好好作者: tt2008 时间: 2008-8-2 00:23
hhhhhhhhhhhhhhh作者: misslu 时间: 2008-8-19 14:16
anyway,thanks for your share.作者: ttyttt 时间: 2008-11-4 11:10 标题: robot取excel表格参数脚本,并把结果写入excel,其中还包含结果判断 http://www.cnblogs.com/ttyttt/archive/2008/08/31/1280812.html
robot取excel表格参数脚本
declare function getdata(namex as integer,namey as integer) as string
declare function setdata(resultx as integer,resulty as integer,pa as string) as string
'$include "sqautil.sbh" '头包含
Sub Main
Dim Result As Integer
dim pass as String
dim pa as string
dim count as Integer
dim con as integer
For count=1 To 2 '在excel表里取三行数据
for con=1 to 2 '在excel表里取三列数据
'name1 = worksheet.Cells(count,1).Value '从表中取具体行列对应的值
pass=getdata(count,con)
pa=setdata(count,con+9,pass)
msgbox pass
next con
next count
End Sub
'********************以下为自定义函数****************************
function getdata(namex as integer,namey as integer) '设置excel数据
dim excel as Object '定义对象
dim book as Object
dim worksheet as Object
dim na as string
on error resume next
Set excel = GetObject("excel.application") '设置excel变量为execl对象
if(excel Is Nothing) then '判断是否设置成功
Set excel = CreateObject("excel.application") '创建excel对象
if(excel Is Nothing) then '判断是否创建成功
MsgBox "Couldn't find Excel!"
End if
End if
'msgbox "成功"
Set book = excel.Workbooks.Open("d:\qin.xls") '打开具体Excel文件,这里是我d盘下一个名为qingd的xls文件
Set worksheet = book.Worksheets("1") '设置工作的表,工作表的名字为1
na=worksheet.Cells(namex,namey).Value
getdata=na
excel.Quit '关闭excel
Set excel = Nothing '把excel对象设置为空
end function
'************************************/
'/////////////////////////////
function setdata(resultx as integer,resulty as integer,pa as string)
dim excel1 as Object '定义对象
dim book1 as Object
dim worksheet1 as Object
on error resume next
Set excel1 = GetObject("excel.application") '设置excel变量为execl对象
if(excel1 Is Nothing) then '判断是否设置成功
Set excel1 = CreateObject("excel.application") '创建excel对象
if(excel1 Is Nothing) then '判断是否创建成功
MsgBox "Couldn't find Excel!"
End if
End if
'msgbox "成功"
Set book1 = excel1.Workbooks.Open("d:\qin.xls") '打开具体Excel文件,这里是我d盘下一个名为qingd的xls文件
Set worksheet1 = book1.Worksheets("1") '设置工作的表,工作表的名字为1
worksheet1.Cells(resultx,resulty).Value=pa
open "D:\2.txt" for append as #2
write #2,pa
excel1.Quit '关闭excel
Set excel1 = Nothing '把excel对象设置为空
end function