<wbr></wbr>
在调试QTP脚本过程中发现,无论是Qtp自带的运行报告还是TD提供的运行报告,都无法为错误定位提供很确切、直观的参考。比如,有时错误发生在点击“订单填写”的步骤,而运行报告给出的结果是无法找到点击“订单填写”步骤之后的订单填写界面对象的缺失。因此为了更好地保留“现场”,我们在场景恢复关闭进程函数之前,先调用桌面截图函数保留“案发现场”。desktop.CaptureBitmap<wbr><wbr>filename,Ture。</wbr></wbr>
通常一个测试集中包含很多个测试用例,为了方便用例和截图的对应,要对截图的命名区分处理。麦兜兜想到两种方式:
一、返回错误发生时系统当前时间,如下所示:
<wbr>Dim<wbr>FileName<wbr>,TimeNow,<wbr>ResPath</wbr></wbr></wbr></wbr>
<wbr>ResPath<wbr>=<wbr>"D:\TestsResult"</wbr></wbr></wbr>
<wbr>TimeNow<wbr>=<wbr>DotNetFactory.CreateInstance(<wbr>"System.DateTime"<wbr>).Now.ToString(<wbr>"ddMMyyHHmmss"<wbr>)</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr>FileName<wbr>=<wbr>ResPath<wbr>&<wbr>""<wbr>&<wbr>TimeNow<wbr>&<wbr>".bmp"</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr>desktop.CaptureBitmap<wbr><wbr>filename,True</wbr></wbr></wbr>
<wbr></wbr>
二、从环境变量获取当前测试脚本的名称,如下所示:
<wbr>Dim<wbr>FileName<wbr>,ResPath</wbr></wbr></wbr>
<wbr>ResPath<wbr>=<wbr>"D:\TestsResult"</wbr></wbr></wbr>
<wbr><span style="word-wrap:normal; word-break:normal; font-size:10.5pt">TestNameNow</span><span style="word-wrap:normal; word-break:normal; font-size:10.5pt">=environment.Value("TestName")<wbr><wbr></wbr></wbr></span></wbr>
<wbr>FileName<wbr>=<wbr>ResPath<wbr>&<wbr>""<wbr>&<wbr><span style="word-wrap:normal; word-break:normal; font-size:10.5pt">TestNameNow</span><wbr>&<wbr>".bmp"</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr>desktop.CaptureBitmap<wbr><wbr>filename,True</wbr></wbr></wbr>
当然也可将二者结合。
******************************************************************************
有博友留言想了解整体函数,下面提供:
public Function RecoveryFunction1(Object, Method, Arguments, retVal)
Dim<wbr>FileName<wbr>,TimeNow,<wbr>ResPath</wbr></wbr></wbr>
ResPath<wbr>=<wbr>"D:\TestsResult"</wbr></wbr>
TimeNow<wbr>=<wbr>DotNetFactory.CreateInstance(<wbr>"System.DateTime"<wbr>).Now.ToString(<wbr>"ddMMyyHHmmss"<wbr>)</wbr></wbr></wbr></wbr></wbr></wbr>
TestNameNow=environment.Value("TestName")<wbr></wbr>
FileName<wbr>=<wbr>ResPath<wbr>&<wbr>""&<span style="word-wrap:normal; word-break:normal; font-size:10.5pt"><span style="word-wrap:normal; word-break:normal; font-size:10.5pt">TestNameNow</span></span><wbr>&<wbr>TimeNow<wbr>&<wbr>".bmp"</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
desktop.CaptureBitmap<wbr><wbr>filename,True</wbr></wbr>
systemutil.closedescendentprocesses<wbr><br><wbr><wbr><wbr>End Function</wbr></wbr></wbr></wbr>
******************************************************************************