在成功安装和建立测试项目以后,就可以利用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: 2006-12-23 15:22:57 'scrīpt Name: test-calc StartApplication "c:\windows\system32\calc.exe" Window SetContext, "Caption=计算器", "" PushButton Click, "Text=7" PushButton Click, "Text=+" PushButton Click, "Text=6" PushButton Click, "Text==" Result = EditBoxVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Value=130000") Window CloseWin, "", "" End Sub |
Result = EditBoxVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Value=130000") |
改为:
Result = EditBoxVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric;Value=13") |
这样就可以点击工具栏上的回放按钮进行回放。
这个脚本只能验证一组数据,并不能体现出自动化测试带来的便利。需要对脚本进行手工修改,在脚本加入循环结构和数据池(DATAPOOL),这样就可以实现一个脚本测试大量的数据,脚本易于维护而且功能强大。
修改后的脚本如下:
'$Include "sqautil.sbh" //datapool必须写的第一句话 Sub Main Dim Result As Integer dim m as string dim x as integer dim n as string dim sum as variant dim dp as long 'Initially Recorded: 2006-12-23 15:22:57 'scrīpt Name: test-calc StartApplication "c:\windows\system32\calc.exe" dp=SQADatapoolOpen("Book1") for x=1 to 5 Call SQADatapoolFetch(dp) Call SQADatapoolValue(dp,1,m) Call SQADatapoolValue(dp,2,n) Call SQADatapoolValue(dp,3,sum) Window SetContext, "Caption=计算器", "" InputKeys m &"{+}"& n &"{ENTER}" 注释:/*只点与上面的区别: PushButton Click, "Text=7" PushButton Click, "Text=+" PushButton Click, "Text=6" PushButton Click, "Text==" */ Result = EditBoxVP (CompareNumeric, "ObjectIndex=1", "VP=Alphanumeric; Value="& sum &"") Window ResetTestContext, "", "" if Result<>1 then SQALogMessage sqaFail, "测试失败", "设计测试失败" else SQALogMessage sqaPass, "测试成功", "" end if msgbox Result //提示信息 next Call SQADatapoolClose(dp) Window CloseWin, "", "" End Sub |