<h1>QTP自动统计客户端崩溃次数</h1>
这是上次SVR客户端那边的一个自动化测试需求,将代码分享在这里。
<pre class="brush: vb">
'统计崩溃次数脚本
Dim MyTimes
'声明API
Extern.Declare micLong,"IsHungAppWindow","user32.dll","IsHungAppWindow",micLong
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'使用方法,先调用一次Toggle
call Toggle()
'想执行多少次,就在参数中直接填写(次数-1)
Call countcrash(39)
'结果呈现
msgbox "失败次数为" & cstr (MyTimes)
Function countcrash(j)
For i=1 to j
'尝试等待一段时间
wait 15
'调用API获取句柄和进程状态
hwnd = Extern.FindWindow(vbNullString,"SVR录播主机客户端")
wait 10
MyFlag=Extern.IsHungAppWindow(hwnd)
wait 5
If MyFlag=1 Then
'记录失败记录一次
MyTimes=MyTimes+1
'调用一次Toggle
call Toggle()
else
'记录成功记录一次
sucTimes= sucTimes+1
'继续调用一次Toggle
call Toggle()
End if
Next
End Function
Function Toggle()
'尝试重新执行SVR客户端程序
'***********step 1 杀进程************
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "taskkill /F /IM lbcon.*",0,1
'***********step 2 起进程************
SystemUtil.Run "C:\Program Files\SVR录播系统\lbcon.exe"
End Function
</pre>