﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-咚咚咚-文章分类-工具使用</title><link>http://www.cnitblog.com/tab1002/category/1737.html</link><description>静静聆听内心世界的声音　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　
常常有令人欢喜的旋律响起




　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　可以简单、可以深沉





　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　可以抒情、可以喧哗</description><language>zh-cn</language><lastBuildDate>Sat, 01 Oct 2011 12:03:32 GMT</lastBuildDate><pubDate>Sat, 01 Oct 2011 12:03:32 GMT</pubDate><ttl>60</ttl><item><title>Rational Robot的启动</title><link>http://www.cnitblog.com/tab1002/articles/7045.html</link><dc:creator>咚咚咚</dc:creator><author>咚咚咚</author><pubDate>Wed, 01 Mar 2006 03:18:00 GMT</pubDate><guid>http://www.cnitblog.com/tab1002/articles/7045.html</guid><wfw:comment>http://www.cnitblog.com/tab1002/comments/7045.html</wfw:comment><comments>http://www.cnitblog.com/tab1002/articles/7045.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/tab1002/comments/commentRss/7045.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/tab1002/services/trackbacks/7045.html</trackback:ping><description><![CDATA[<TABLE cellSpacing=0 cellPadding=0 width=558 border=0>
<TBODY>
<TR>
<TD vAlign=top align=right colSpan=2 height=10>
<DIV align=center><SPAN style="FONT-SIZE: 12pt"><B>Rational Robot的启动</B></SPAN></DIV></TD></TR>
<TR>
<TD vAlign=center align=right colSpan=2 height=20>
<DIV align=center>文章出处：www.51testing.com 作者：朴春龙 发布时间：2005-10-19</DIV></TD></TR>
<TR>
<TD vAlign=top align=right width="2%" height=10>
<DIV align=left></DIV></TD>
<TD vAlign=top align=right width="98%" bgColor=#ffffff>
<DIV class=daxiao14 align=left>
<P><STRONG>【摘要】 </STRONG>随着软件产品在各行业应用越来越广泛，软件质量日益得到重视。提高测试水平，测试效率是广大测试工程师追求的目标。 Rational 的产品涉及到软件工程各个部分，本文从实际出发介绍控制启动自动化工具 Robot 的方法。文中涉及开发，系统几个方面，希望提供大家一个完美的解决方案。 </P>
<P><STRONG>【关键字】 </STRONG>软件测试 自动化测试 Rational Robot 系统启动 </P>
<P>这篇文章是基于论坛上一个问题 “ 如何让脚本定时运行 ” ，提供的一个解决方案。我们都听说过自动化测试应用于每日构建，每天在 下班之后编译版本，定时启动自动化测试脚本进行功能测试，第二天相关人员收到相应的报告。但是如何启动自动化测试工具呢，这里主要针对于 Rational Robot 的提供一种实现方法。 </P>
<P>因为 Rational Robot 支持从命令行启动脚本，所以我们很容易在命令行中启动它。具体参考 Rational Robot User's Guide 。基本的命令行语法结构如下： </P>
<P>Rtrobo.exe [scriptname] [/user userid] [/password PassWrod] [/project Full - path- and – full - projectname] [/play] [/purify] [/quantify] [/coverage] [/build build] [/logfolder foldername] [/log logname] [/nolog] [/close]</P>
<TABLE cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD vAlign=top width=223>
<P>元素 </P></TD>
<TD vAlign=top width=345>
<P>描述 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>Rtrobo.exe </P></TD>
<TD vAlign=top width=345>
<P>Rational robot 执行文件 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>scriptname </P></TD>
<TD vAlign=top width=345>
<P>要运行的脚本名称 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/user userid </P></TD>
<TD vAlign=top width=345>
<P>登陆用户名 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/password password </P></TD>
<TD vAlign=top width=345>
<P>登陆用户名密码，如果用户名没有密码，不用该参数 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/Project full path and full projectname </P></TD>
<TD vAlign=top width=345>
<P>包含脚本的工程名字和工程路径 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/play </P></TD>
<TD vAlign=top width=345>
<P>如果指定了关键字，运行 scriptname 指定的脚本，如果没有指定，只是在编辑器中打开脚本 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/purify </P></TD>
<TD vAlign=top width=345>
<P>和 /play 参数一起使用，在 rational Purify 下回放 scriptname 参数指定的脚本 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/quantify </P></TD>
<TD vAlign=top width=345>
<P>和 /play 参数一起使用，在 rational quantify 下回放 scriptname 参数指定的脚本 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/coverage </P></TD>
<TD vAlign=top width=345>
<P>和 /play 参数一起使用，在 rational purecoverage 下回放 scriptname 参数指定的脚本 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/build build </P></TD>
<TD vAlign=top width=345>
<P>脚本编译名字 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/logfolder foldername </P></TD>
<TD vAlign=top width=345>
<P>存放测试日志文件的文件夹名称，日志文件夹和 build 参数相关联 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/log logname </P></TD>
<TD vAlign=top width=345>
<P>日志文件名称 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/nolog </P></TD>
<TD vAlign=top width=345>
<P>当脚本回放时不输出任何日志文件 </P></TD></TR>
<TR>
<TD vAlign=top width=223>
<P>/close </P></TD>
<TD vAlign=top width=345>
<P>回放脚本后关闭 robot </P></TD></TR></TBODY></TABLE>
<P>例：用户 admin 启动 testProject 工程脚本 test ，命令行语法如下： </P>
<P>rtrobo.exe test /user admin /project c:\Program\robot\testDelphi\testProject.rsp /play </P>
<P>那如何定时启动呢，在 Windows 系统中有 “ 任务计划 ” 提供了定时启动功能，通过它可以预定一些软件在规定的时间运行。利用 “ 任务计划 ” ，可以将任何脚本、程序或文档安排在某个最方便的时间运行。 “ 任务计划 ” 在每次启动 Windows 的时候开始启动并在后台运行。那么我们完全可以利用它来完成 “ 不可能的任务 ” 。 </P>
<P>在计划任务中添加任务那么就可以定时启动 Rational robot 运行脚本。操作如下： </P>
<P>1 ．开始 - 〉设置 - 〉控制面板 </P>
<P>2 ．打开计划任务向导 </P>
<P>3 ．添加启动任务，设置启动时间 </P>
<P>4 ．修改计划任务运行中参数如下： </P>
<P>"c:\Program Files\Rational\Rational Test\rtrobo.exe" test /user admin /project c:\Program\robot\testDelphi\testProject.rsp /play </P>
<P>Rational Robot 在预定时间定时启动了。问题得到解决。 </P>
<P>备注： 运行过程中仍需要设置相关参数，否则阻止运行。比如默认情况下，脚本运行都会启动编译窗口。这里除了命令行设置参数外还可以设置 Robot 中 GUI Playback Option 窗体的 log 页面 use default log information 项。这样在无人职守的情况下，启动测试工具不会由于测试工具自身设置中止运行。 </P>
<P>但是实际工作需要更加灵活的功能，比如曾经笔者所在公司开发软件为组态监控软件，利用组态软件开发的一个项目是控制大厦的空调系统在夜里定时重新启动。进行功能测试时候，我们不可能真的等到夜里才进行测试（估计夜里上班公司也不会批准给加班费 ^_^ ），按照计划任务的实现方法有一定局限性不能随心所欲启动机器进行功能测试。 </P>
<P>熟悉 Windows 编程的人都知道 API 函数 ExitWindowsEx 可以实现重新启动系统的功能 ( 具体的用法参看 MSDN) 。这样只要调用 ExitWindowEx 函数重新启动系统后启动 Rational Robot 运行需要的脚本就可以达到任何时候启动系统继续进行功能测试的目的。 </P>
<P>一般情况下登陆系统时需要输入登陆名和密码，如果不能自动登陆，那么就成为运行脚本进行测试的障碍。在注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 位置添加 DefaultDomainName,DefaultUserName,DefaultPassword 三项，赋予相应的值。重新启动系统后自动登陆。 </P>
<P>那么最后面对的一个问题就是怎样让 robot 随着系统而启动。这个相对来说比较简单，在系统开始启动菜单中建立一个快捷方式就可以实现随着系统启动的功能，其实就是在注册表 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 中添加键值。附录提供笔者实现的 robot 脚本代码供大家参考。 </P>
<P>Brian Bryson 提供组件 – RobotHelperComponent 帮助我们实现利用 Robot 重新启动系统并启动 Rational Robot 运行脚本的功能。该组件下载地址为： </P>
<P><A href="http://www-106.ibm.com/developerworks/rational/library/content/03July/2000/2155/2155_RobotHelperComponent.zip">http://www-106.ibm.com/developerworks/rational/library/content/03July/2000/2155/2155_RobotHelperComponent.zip</A></P>
<P>关于该组件的介绍请看 Brian Bryson 的 Rebooting Your System 一文。该文地址： </P>
<P><A href="http://www-106.ibm.com/developerworks/rational/library/959.html">http://www-106.ibm.com/developerworks/rational/library/959.html</A></P>
<P>本文到此告以结束，希望大家对于 Rational Robot 的启动问题有了一个满意的答案。 </P>
<P>参考： </P>
<P>•&nbsp; Microsoft MSDN2003 </P>
<P>•&nbsp; Rational Robot User Guide </P>
<P>•&nbsp; Rational Robot Tips and Techniques: Rebooting Your System – 作者 Brian Bryson </P>
<P>附录：</P>
<P>Const REG_SZ=1 </P>
<P>Global Const HKEY_LOCAL_MACHINE = ＆ H80000002 </P>
<P>Declare Function RegOpenKey Lib“advapi 32” Alias “RegOpenKeyA”(ByVal hkey As Long, ByVal lpszSubKey As String,phkResult As Long) As Long</P>
<P>Declare Function RegSetValueEx Lib “advapi 32” Alias “RegSetValueExA” (ByVal hkey As Long,ByVal lpszValueName As String,ByVal dwReserved As Long,ByVal fdwType As Long, lpbData As Any,ByVal cbData As Long) As Long</P>
<P>Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long</P>
<P>Declare Function RegCloseKey Lib “advapi 32” Alias “RegCloseKey” (ByVal hkey As Long) As Long</P>
<P>编写功能函数</P>
<P>Function oRegOpenKey (ByVal hkey As Long, ByVal lpszSubKey As String,phkResult As Long) As Boolean </P>
<P>Dim lResult As Long </P>
<P>On Error GoTo 0 ' 错误跳转 </P>
<P>lResult=RegOpenKey(hkey,lpszSubKey,phkResult) </P>
<P>If lResult=0 Then </P>
<P>oRegOpenKey=True </P>
<P>Else oRegOpenKey=False </P>
<P>End If </P>
<P>End Function</P>
<P>Function RegSetStringValue(ByVal hKey As Long, ByVal strValueName As String, ByVal strData As String, Optional ByVal fLog) As Boolean </P>
<P>Dim lResult As Long </P>
<P>On Error GoTo 0 </P>
<P>lResult = RegSetValueEx(hKey, strValueName, 0&amp;, REG_SZ, ByVal strData, LenB(StrConv(strData, vbFromUnicode)) + 1) </P>
<P>If lResult = 0 Then </P>
<P>RegSetStringValue = True </P>
<P>Else </P>
<P>RegSetStringValue = False </P>
<P>End If</P>
<P>End Function</P>
<P>调用函数测试代码 </P>
<P>Sub Main</P>
<P>Dim hkey As Long </P>
<P>Dim MyReturn As Long </P>
<P>MyReturn=oRegOpenkey(HKEY_LOCAL_MACHINE, </P>
<P>“SOFTWARE\Microsoft\Windows\CurrentVersion\Run”,hkey) </P>
<P>If hkey=0 Then </P>
<P>MsgBox “ 主键未创建或者输入有误，请仔细核对后再次运行本程序！ ” </P>
<P>Exit Sub </P>
<P>End If </P>
<P>MyReturn=RegSetStringValue(hkey, “robot”,“”” 路径 / rtrobo.exe”” test /user admin /project c:\Program\robot\testDelphi\testProject.rsp /play ”,False)</P>
<P>If MyReturn Then </P>
<P>MsgBox “ 您的程序已成功添加到系统启动中，再次启动 Windows 时系统将自动运行您的程序！ ” </P>
<P>Else </P>
<P>MsgBox “ 代码中存在错误 ” </P>
<P>End If </P>
<P>RegCloseKey(hkey)</P>
<P>End Sub</P>
<P>以上代码在 Rational Robot 2002 上测试通过。<BR></P></DIV></TD></TR></TBODY></TABLE><img src ="http://www.cnitblog.com/tab1002/aggbug/7045.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/tab1002/" target="_blank">咚咚咚</a> 2006-03-01 11:18 <a href="http://www.cnitblog.com/tab1002/articles/7045.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用ACT进行测试</title><link>http://www.cnitblog.com/tab1002/articles/5871.html</link><dc:creator>咚咚咚</dc:creator><author>咚咚咚</author><pubDate>Thu, 29 Dec 2005 01:31:00 GMT</pubDate><guid>http://www.cnitblog.com/tab1002/articles/5871.html</guid><wfw:comment>http://www.cnitblog.com/tab1002/comments/5871.html</wfw:comment><comments>http://www.cnitblog.com/tab1002/articles/5871.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/tab1002/comments/commentRss/5871.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/tab1002/services/trackbacks/5871.html</trackback:ping><description><![CDATA[ACT简介&nbsp;<BR>ACT（或者MSACT）是微软的Visual&nbsp;Studio&nbsp;和Visual&nbsp;Studio.NET带的一套进行程序测试的工具，也正是我们的负压测试需要用到的。ACT不但可以记录程序运行的详细数据参数，用图表显示程序运行状况，而且安装和使用都比较简单，结果阅读也很方便，是一套较理想的测试工具。&nbsp;<BR>&nbsp;<BR>安装ACT&nbsp;<BR>最起码，当然我们需要Visual&nbsp;Studio，ACT似乎还没有单独的版本出现。在这里，我们测试一个WEB&nbsp;Service的在高负荷情况下的运行性能。首先，在Visual&nbsp;Studio中打开ACT（如图）&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_13.jpg" target=_blank><IMG alt="" src="http://www.ccw.com.cn/htm/center/prog/02_4_13.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0 dypop="按此在新窗口浏览图片"></A>&nbsp;<BR>程序会提示是否建立一个新的工程，点击“是”，然后输入一个文字说明，出现以下界面（图二）：&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_11.jpg" target=_blank><IMG alt="" src="http://www.ccw.com.cn/htm/center/prog/02_4_11.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0 dypop="按此在新窗口浏览图片"></A><BR>&nbsp;<BR>打开ACT以后，我们可以开始测试了。&nbsp;<BR>&nbsp;<BR>建立一个新的测试&nbsp;<BR>点击菜单【Action】－&gt;【New&nbsp;Test】（如图三）&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_14.jpg" target=_blank><IMG alt=按此在新窗口浏览图片 src="http://www.ccw.com.cn/htm/center/prog/02_4_14.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0></A>
<P><BR>会出现一个向导界面（图四）&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_15.jpg" target=_blank><IMG alt="" src="http://www.ccw.com.cn/htm/center/prog/02_4_15.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0 dypop="按此在新窗口浏览图片"></A></P>
<P><BR>向导我们太熟悉了，仔细阅读每个界面的说明文字，&nbsp;选择就可以了。&nbsp;<BR>&nbsp;<BR>编辑测试&nbsp;<BR>经过以上的设置，会出现以下界面（图五）：&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_16.jpg" target=_blank><IMG alt="" src="http://www.ccw.com.cn/htm/center/prog/02_4_16.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0 dypop="按此在新窗口浏览图片"></A><BR>&nbsp;<BR>很明显，以上界面我们人为的将它分为了三个部分，而且每个部分颜色各不相同。以上不同颜色的三个部分分别为：&nbsp;<BR>左边蓝色部分：导航栏，测试入口和结果人口；&nbsp;<BR>右上绿色：提示信息栏；&nbsp;<BR>右下红色：VBS代码栏，在这里编辑测试需要的一些VBS代码，测试成功有效与否，全部依靠这些代码的执行情况。所以，这些代码最好仔细考虑并且多次测试；&nbsp;<BR>在进行测试之前，首先设置测试的一些选项（菜单【Action】—&gt;【Properties】）如图六&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_17.jpg" target=_blank><IMG alt="" src="http://www.ccw.com.cn/htm/center/prog/02_4_17.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0 dypop="按此在新窗口浏览图片"></A></P>
<P><BR>在以上界面，主要设置两个参数：&nbsp;<BR>（1）&nbsp;Test&nbsp;duration设置，这里设置测试进行时间，默认为5分钟；&nbsp;<BR>（2）&nbsp;在Counters标签页设置一些测试性能数据；&nbsp;<BR>以上设置完成以后，就可以开始修改VBS代码了，我们没必要遍历整个VBS代码，只看一些主要的：&nbsp;<BR>Test.SendRequest("<IMG src="http://www1.testage.net/bbs/pic/url.gif" align=absMiddle border=0><A href='http://localhost/"' target=_blank><FONT color=#000000>http://localhost/"</FONT></A>;)&nbsp;<BR>以上是默认代码，我们可以修改为以下代码：&nbsp;<BR>Test.SendRequest("<IMG src="http://www1.testage.net/bbs/pic/url.gif" align=absMiddle border=0><A href='http://localhost/philipq/wsmessages/wsmsg.asmx/MPost?webKey=w2k&amp;UName=Ad&amp;UPassword=pwd&amp;UTo=Admin&amp;UMessage=ACT+Test"' target=_blank><FONT color=#000000>http://localhost/philipq/wsmessages/wsmsg.asmx/MPost?webKey=w2k&amp;UName=Ad&amp;UPassword=pwd&amp;UTo=Admin&amp;UMessage=ACT+Test"</FONT></A>;)&nbsp;<BR>以上代码的编写应该根据自身程序的特点来修改，以达到最好测试效果。&nbsp;<BR>&nbsp;<BR>执行测试&nbsp;<BR>点击工具栏的【Start】按钮开始测试如图）：&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_18.jpg" target=_blank><IMG alt=按此在新窗口浏览图片 src="http://www.ccw.com.cn/htm/center/prog/02_4_18.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0></A></P>
<P><BR>测试进行的时候，会出现以下窗口提示（如图）：&nbsp;<BR>&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_19.jpg" target=_blank><IMG alt="" src="http://www.ccw.com.cn/htm/center/prog/02_4_19.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0 dypop="按此在新窗口浏览图片"></A></P>
<P><BR>以上界面显示程序测试的时间、剩余时间、每秒提交的Request数量、提交的Request总量、错误数量等。点击按钮【Show&nbsp;details】可以查看详细数据。&nbsp;<BR>测试结束以后，就可以查看测试的结果了。&nbsp;<BR>&nbsp;</P>
<P>阅读测试结果&nbsp;<BR>测试完成以后，可以在图二左边的Result分支点击查看测试结果，在右方的报表栏我们可以查看到以下数据：OverView、Graphs、Requests等，下图是一个OverView的数据举例：&nbsp;<BR>&nbsp;&nbsp;<A onfocus=this.blur() href="http://www.ccw.com.cn/htm/center/prog/02_4_110.jpg" target=_blank><IMG alt="" src="http://www.ccw.com.cn/htm/center/prog/02_4_110.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" border=0 dypop="按此在新窗口浏览图片"></A></P>
<P><BR>从以上报告可以看到，测试的程序每秒提交request23次，总共1400次。&nbsp;<BR>&nbsp;<BR>测试结果的使用&nbsp;<BR>根据测试的结果，我们可以知道程序运行的情况、在高负荷下服务器的承受能力。根据这些数据，我们来确定程序的性能和服务器的性能，以此来预测在程序正式使用以后可能遇到的情况和服务器需要的改进。&nbsp;<BR></P><img src ="http://www.cnitblog.com/tab1002/aggbug/5871.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/tab1002/" target="_blank">咚咚咚</a> 2005-12-29 09:31 <a href="http://www.cnitblog.com/tab1002/articles/5871.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>