海龙 2004-5-6 21:42
Robot功能测试示例
在成功安装和建立测试项目以后,就可以利用testmanager和robot进行软件测试了。下面以一个windows自带的计算器测试例子,展示rational的功能。
1. 启动robot,登录窗口默认用户名是admin,输入在建立测试项目时指定的密码(默认为空),即可进入robot主界面;
2. 点击工具栏上的GUI按钮,录制GUI脚本,在窗口中输入脚本名称;
3. 在GUI Record工具栏上点击第四个按钮,在GUI Inset工具栏点击Start Application按钮,点击browse…按钮,选择计算器程序;
4. 从键盘输入1+1=,然后在GUI Record工具栏上点击第四个按钮,在GUI Inset工具栏点击Alphanumeric校验点,选择第三项Numeric Equivalence;
5. 关闭计算器,点击GUI Record工具栏上的STOP按钮,完成脚本的录制;
录制完的脚本:
Sub Main
Dim Result As Integer
'Initially Recorded: 2003-7-18 9:30:45
'Script Name: 计算器
StartApplication "C:\WINNT\system32\calc.exe"
Window SetContext, "Caption=计算器", ""
InputKeys "1{+}1{ENTER}"
Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
Window CloseWin, "", ""
End Sub
这个脚本并不能正确回放,需要将
Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
改为:
Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=2.")
这样就可以点击工具栏上的回放按钮进行回放。
这个脚本只能验证一组数据,并不能体现出自动化测试带来的便利。需要对脚本进行手工修改,在脚本加入循环结构和数据池(DATAPOOL),这样就可以实现一个脚本测试大量的数据,脚本易于维护而且功能强大。
修改后的脚本如下:
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim dp as long
dim x as integer
dim num1 as string
dim num2 as string
dim sum as string
'Initially Recorded: 2003-7-18 8:51:18
'Script Name: 计算器-2
StartApplication "C:\WINNT\system32\calc.exe"
dp=SQADatapoolOpen("jsq")
for x=1 to 5
Call SQADatapoolFetch(dp)
Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
Window SetContext, "Caption=计算器", ""
InputKeys num1 &"{+}"& num2 &"{ENTER}"
Result = LabelVP (CompareNumeric, "Text="& sum &".", "VP=Alphanumeric;Value="& sum &".")
next
Call SQADatapoolClose(dp)
Window CloseWin, "", ""
End Sub
注:SQADatapoolOpen("jsq"),jsq为数据池(DATAPOOL)名称,需要在testmanager中手工创建。
**经过简单的编辑后,测试时只需要将测试数据导入数据池(DATAPOOL)回放脚本即可,通过查看测试log检查哪些错误,在开始测试时就可以使用,而不是等到回归,也不是手工过程的简单重复。在测试之前,可以先准备好测试数据备用。
我在实际的测试工作中,功能测试的脚本大部分是基于此模式的,使用效果也很理想。
这个帖子我在测试管理中心也发过,有些网友反映不能正确回放。以上是我在windows2000专业版、rational2003上重新录制并正确回放的的。
欢迎大家交流。
[[i] Last edited by 海龙 on 2004-7-30 at 22:33 [/i]]
小颖_hlj 2004-7-23 14:34
对于dp你没有定义,
小颖_hlj 2004-7-23 14:50
数据池如何定义的
你的jsq如何定义的,
定义了几列,为什么对sum也定义一列
ivy5156 2004-7-28 15:27
num1,num2在datapool中该取何种类型?String吗?
num1,num2在datapool中该取何种类型?String吗?
为什么取出来都是一样的随机数据
sum能自动计算出来吗?
[ Last edited by ivy5156 on 2004-7-28 at 15:28 ]
houna305 2004-8-8 21:45
我得也不能正常进行
ghost 2004-8-9 09:32
取整型,设定不同的Seed就可以了。
ivy5156 2004-8-10 16:49
如果都是自动生成的,当然也可以自己改动,如果我要随即100条数据,难道所有的 seed都要我自己写嘛
houna305 2004-8-12 11:52
我的可以自动进行运算器的计算和测试,测试结果也是正确的的,但就是运行的很慢,是超慢,是为什么呢,希望大家多多指点啊
pcl2004_27 2004-8-18 12:28
时间慢,你把robot的回放参数时间间隔修改一下!减少时间间隔,试验一下!
llmmgl 2004-10-9 16:35
对“Robot功能测试示例”文章不明白的地方。请版主回答,谢谢!
1、dp要怎么定义?
2、数据池jsq该怎么定义才行?
3、 Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
这几个SQA语句中的1、2、3表示什么
hxf 2004-10-9 16:47
1、dp要怎么定义?
dim dp as long
2、数据池jsq该怎么定义才行?
在testmanager中定义。
3、 Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
这几个SQA语句中的1、2、3表示什么
从datapool中取第几个字段的值。
fjzpdjn 2004-10-27 15:22
为什么提示 "varibale SQADatapoolOpen undefined',我已建立了JSQ数据池了,是不是数据池文件要放在哪个目录下才行
fjzpdjn 2004-10-27 17:10
能帮解答:为什么把 dp设为 long类型
能帮解答:为什么把 dp设为 long类型
gezi68705 2004-11-4 13:29
请教大侠:为什么我录制的脚步是这样的?
Sub Main
Dim Result As Integer
'Initially Recorded: 2004-11-4 13:21:58
'Script Name: 计算器
StartApplication "C:\WINNT\system32\calc.exe"
Window SetContext, "Caption=计算器", ""
InputKeys "1{+}1{ENTER}"
Window SetContext, "Class=Shell_TrayWnd", ""
TabControl Click, "ObjectIndex=1;\;ItemIndex=3", ""
End Sub
点停止按钮后提示:there is no text in field or field cannot be read.
这是那里没有配置好呀?
gezi68705 2004-11-5 16:55
请海龙版主或各位大侠帮忙指点以下!
暗夜之吻 2004-11-9 10:01
Result = LabelVP (CompareNumeric, "Text="& sum &".", "VP=Alphanumeric;Value="& sum &".")
如果text和value的值都从datapool中取的话,那比较的结果也没有什么意义啊?
Daven520 2004-11-12 12:03
还是不行~~~
jakedd 2004-12-20 15:32
[quote]Originally posted by [i]gezi68705[/i] at 2004-11-4 01:29 PM:
请教大侠:为什么我录制的脚步是这样的?
Sub Main
Dim Result As Integer
'Initially Recorded: 2004-11-4 13:21:58
'Script Name: 计算器
StartApplication "C:\WINNT\system32\ ... [/quote]
我也是这个问题,该怎么解决呢?脚本里根本没有检测点啊
jakedd 2004-12-21 09:17
原来是检测点没选对象引起的,现在好了
hailong1977 2005-1-25 09:51
请问海龙?
我用rational2002录制的脚本和你的一样,只有一处
你的:Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
我的:Result = LabelVP (CompareNumeric, "ObjectIndex=1","VP=Alphanumeric;Value=200000")
第一次按我的回放,“pass”。可建了datapool后,这里我就不知道怎么改了。
同时我按你那个例子,在datapool见建了3列,num1、num2、sum,分别添了数据。可回放出错。下面是我的脚本,麻烦看看。
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim dp as long
dim x as integer
dim num1 as string
dim num2 as string
dim sum as string
'Initially Recorded: 2005-1-25 9:06:14
'Script Name: data1
StartApplication "C:\WINNT\system32\calc.exe"
dp=SQADatapoolOpen("jsq")
for x=1 to 5
Call SQADatapoolFetch(dp)
Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
Window SetContext, "Caption=计算器", ""
InputKeys num1 &"{+}"& num2 &"{ENTER}"
Result = LabelVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Value="& sum &".")
next
Call SQADatapoolClose(dp)
Window CloseWin, "", ""
End Sub
hailong1977 2005-1-25 09:52
请问海龙?
我用rational2002录制的脚本和你的一样,只有一处
你的:Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
我的:Result = LabelVP (CompareNumeric, "ObjectIndex=1","VP=Alphanumeric;Value=200000")
第一次按我的回放,“pass”。可建了datapool后,这里我就不知道怎么改了。
同时我按你那个例子,在datapool见建了3列,num1、num2、sum,分别添了数据。可回放出错。下面是我的脚本,麻烦看看。
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim dp as long
dim x as integer
dim num1 as string
dim num2 as string
dim sum as string
'Initially Recorded: 2005-1-25 9:06:14
'Script Name: data1
StartApplication "C:\WINNT\system32\calc.exe"
dp=SQADatapoolOpen("jsq")
for x=1 to 5
Call SQADatapoolFetch(dp)
Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
Window SetContext, "Caption=计算器", ""
InputKeys num1 &"{+}"& num2 &"{ENTER}"
Result = LabelVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Value="& sum &".")
next
Call SQADatapoolClose(dp)
Window CloseWin, "", ""
End Sub
hailong1977 2005-1-25 10:00
请问海龙?
我用rational2002录制的脚本和你的一样,只有一处
你的:Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
我的:Result = LabelVP (CompareNumeric, "ObjectIndex=1","VP=Alphanumeric;Value=200000")
第一次按我的回放,“pass”。可建了datapool后,这里我就不知道怎么改了。
同时我按你那个例子,在datapool见建了3列,num1、num2、sum,分别添了数据。可回放出错。下面是我的脚本,麻烦看看。
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim dp as long
dim x as integer
dim num1 as string
dim num2 as string
dim sum as string
'Initially Recorded: 2005-1-25 9:06:14
'Script Name: data1
StartApplication "C:\WINNT\system32\calc.exe"
dp=SQADatapoolOpen("jsq")
for x=1 to 5
Call SQADatapoolFetch(dp)
Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
Window SetContext, "Caption=计算器", ""
InputKeys num1 &"{+}"& num2 &"{ENTER}"
Result = LabelVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Value="& sum &".")
next
Call SQADatapoolClose(dp)
Window CloseWin, "", ""
End Sub
阿蓝 2005-2-22 14:38
[quote]Originally posted by [i]hailong1977[/i] at 2005-1-25 10:00 AM:
我用rational2002录制的脚本和你的一样,只有一处
你的:Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
我的:Result = LabelVP (CompareNumeric, &quo ... [/quote]
把你的那行改成 Result = LabelVP (CompareNumeric, "Type=Label;ObjectIndex=1", "VP=Alphanumeric;Value="& sum &".")
试试
爱吃苹果 2005-3-14 10:22
在第一次录制脚本中,设置验证点的时候我的不和你的一样,
Result = LabelVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Wait=2,30;Value=200000")(我的)
Result = LabelVP( mpareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
我在设置验证点的时候不知道选择哪个控件,请指点
heather 2005-3-30 17:03
我看了上面的程序,在我的机子上也运行了的。
我看了上面的程序,在我的机子上也运行了的。但是在运行数据池的时候,运算结果是对的,但是为什么test log里却不是pass呢?
heather 2005-3-30 17:07
我运行的同hailong1977一样,也看了阿蓝的帖子,将其改为Result = LabelVP (CompareNumeric, "Type=Label;ObjectIndex=1", "VP=Alphanumeric;Value="& sum &".") ,但是结果还是不行啊
司空公子 2005-3-31 09:22
你的datapool里有没有设sum的值啊,不然在验证点比较的时候,由于没有比较的baseline,当然会报错。
目标资深测试员 2005-6-14 16:53
[quote]Originally posted by [i]fjzpdjn[/i] at 2004-10-27 05:10 PM:
能帮解答:为什么把 dp设为 long类型 [/quote]
把那段该为试试
Window SetContext, "Caption=计算器", ""
InputKeys "1{+}1{ENTER}"
Result = WindowVP (CompareNumeric, "Caption=计算器", "VP=Alphanumeric;Value=0")
Window SetContext, "Caption=计算器", ""
Window CloseWin, "", ""
目标资深测试员 2005-6-14 16:55
上面那个发错了应该是针对这个发表的
[quote]Originally posted by [i]gezi68705[/i] at 2004-11-4 01:29 PM:
请教大侠:为什么我录制的脚步是这样的?
Sub Main
Dim Result As Integer
'Initially Recorded: 2004-11-4 13:21:58
'Script Name: 计算器
StartApplication "C:\WINNT\system32\ ... [/quote]
你改为这个试试
Window SetContext, "Caption=计算器", ""
InputKeys "1{+}1{ENTER}"
Result = WindowVP (CompareNumeric, "Caption=计算器", "VP=Alphanumeric;Value=0")
Window SetContext, "Caption=计算器", ""
Window CloseWin, "", ""
mgy2005 2005-7-15 14:26
我把 SCRIPT改了一下,在DATAPOOL中只输入num1 和 num2 的值,然后在script 中算出sum的值,再做比较。如何在Datapool 中赋值,我是用下面几步来实现的:(不好意思我用英文,因为我的是英文版)。
1. Open Rational Task Manager.
2. Select Tools-> Manage-> DataPools.
3. Click on New and enter "jsq" as name. Click OK.
4. You will get a message "An Empty datapool called jsq has been registered..." Select Yes
5. Select Insert Before. In the "Data Type Specification jsq" dialogue, enter "B" in the "Name". Select Insert Before again. Enter "A" in the "Name".
6. Click Save.
7. Click Close.
8. Select OK on the message beginning "If you leave the Datapool editor..."
9. In the "Manage Datapools" dialogue, select jsq and press Edit
10. Click on on Edit Datapool Data in the "Datapool Properties" dialogue.
11. Enter three pairs of numbers. There will be one number in each pair for for A and one for B. and click on Save and Close. For example:
A B
1 0
-1 1
15 16
12. Click on OK in the "Datapool Properties" dialogues.
13. Click on Close in "Manage Datapools."
14. Return to the "Rational Robot" and select File and Playback in the Test "CaclTest-2" Script.
15. Click on OK and if it asks you about overwriting a log, click Yes
16. The system will bring up the Test log. Expand "Script Start" You should observe one "Application Start" and three "Verification Point."
17. If you want to see the numbers each time, go to the Test Add script. Just before "Result - EditBoxVP..." enter the line Print "sum is" & sum
18. Then select File and Playback. (Click after viewing each message.)
下面是我的script.
注意我是在WINDOW XP 下测的,所以StartAppUnderNone "C:\WINDOWS\system32\calc.exe"
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim dp as long
dim x as integer
dim num1 as string
dim num2 as string
dim sum as string
'Initially Recorded: 7/13/2005 3:00:36 PM
'Script Name: CaclTest-2
StartAppUnderNone "C:\WINDOWS\system32\calc.exe"
dp=SQADatapoolOpen("jsq")
for x=1 to 3
Call SQADatapoolFetch(dp)
Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
'Call SQADatapoolValue(dp,3,sum)
Window SetContext, "Caption=Calculator", ""
EditBox Click, "ObjectIndex=1", "Coords=301,9"
'InputKeys num1&"{+}"& num2 & "{ENTER}" has mistake?
InputKeys num1 &"{+}"& num2 &"{ENTER}"
sum = str(val(num1) + val(num2))
Print "num1 is" & num1
Print "num2 is" & num2
Print "sum is" & sum
Result = EditBoxVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Value="& sum &",")
next
Call SQADatapoolClose(dp)
Window CloseWin, "", ""
End Sub
tongfenglcz 2005-7-29 15:07
[quote]Originally posted by [i]ghost[/i] at 2004-8-9 09:32 AM:
取整型,设定不同的Seed就可以了。 [/quote]
必须设置sequence为Random,再将Seed设置成不同的值,就可以生成不同的随机数
我的问题:
1、设置为整型,第1次设置长度为 默认15,后觉得数字太大,将长度设置为2。此时如果不设置最大或最小值,为什么生成的数据都大于2位的?难道最大最小值Robot不会通过设置的字段长度自己控制?
2、如果是数字字母类型的,怎样设置,使得生成的数据长度小于等于length的值,我的与length值等值?
谢谢!!!
tongfenglcz 2005-7-29 15:27
[quote]Originally posted by [i]小颖_hlj[/i] at 2004-7-23 02:50 PM:
你的jsq如何定义的,
定义了几列,为什么对sum也定义一列 [/quote]
定义sum我倒是能理解
可是为什么要从datapool调sum的值呢?
Call SQADatapoolValue(dp,3,sum) ???
fishbasking 2005-8-4 16:41
??
是把正确结果和sum字段的值比较吗?我在sum里输的值不等于num1+num2,为什么结果都是pass呢
[[i] Last edited by fishbasking on 2005-8-8 at 09:44 [/i]]
jinyuhifont 2005-12-26 17:42
是不是因为我的是winxp啊
我的result 不是labelVP 而是viewboxVP。
jinyuhifont 2005-12-27 10:38
终于成了
就是情况和30楼heather的情况一样,还要继续研究啊,呵呵 这是我学robot 的开胃菜,还好有点鼓励啊
jinyuhifont 2005-12-27 10:43
关于datapool 论坛里有斑竹 海龙 的文章
[url]http://bbs.51testing.com/viewthread.php?tid=42&fpage=1&highlight=datapool[/url]
fj5400cn1981 2006-1-10 10:45
datapool的取值没有问题,但是请问如何从文件或是xls文件中取值
wangpu 2006-2-13 09:43
Why chose Datapool?
记得手册中有句话“如果你的脚本只运行一次,就可以不用Dataool”。是啊,根据楼主的例子,我完全可以用数组来实现加数据的功能啊。
请问:这种理解对吗?
zhanghaiying911 2006-7-13 17:50
论坛上计算器例子的结果是Result = LabelVP (CompareNumeric, "Text=2.", "VP=Alphanumeric;Value=200000")
而我自己录制的是Result = LabelVP (CompareNumeric, "ObjectIndex=1","VP=Alphanumeric;Value=200000")
请高手告诉我,Text=2.和ObjectIndex=1在此处是表示的什么意思,还有二者有什么关系和区别,我的是ObjectIndex=1,要是我把它改成Text=2.回放也能成功。可是我不明白二者表示的具体意思。
[[i] 本帖最后由 zhanghaiying911 于 2006-7-13 17:52 编辑 [/i]]
zhanghaiying911 2006-7-14 11:43
怎么没人回答呢!!!!!!!