在QTP Test中利用vbs和cmd实现重新启动QTP

Nora ·
更新时间:2024-09-21
· 852 次阅读

  连续长时间执行过QTP或使用QC连续长时间调用QTP的朋友应该会知道,QTP在长时间执行过程中会产生内存泄露。而QTP自身也有一个工具Remote Agent来实现每执行N次来重新启动测试工具释放内存。   但是,不知道是不是我用破解版的原因,如果使用RunTest来调用QC执行QTP时,这个设置的Remote Agent会使得测试失败,并卡死在某一步。所以在这里需要进行手动清理QTP长时间运行过程中产生的内存泄露。   在这里,我所知的清理内存有两种方式,一种是利用一些内存清理工具,一种是通过脚本控制QTP重新启动。   首先说说内存清理工具。在群里下到了一个兄弟共享的内存清理工具memempty.exe,它可以进行定时清理。但是由于QTP执行每个Test的时间都不相同,并且QTP在执行过程中,这个工具也无法有效的清理干净内存部分。对这些不是很懂,点下行了,免得出丑。   使用脚本控制,这里我用的是创建外部vbs并通过cmd命令来执行的方式实现的,脚本如下:

dim restartcode set?fso?=?CreateObject("Scripting.FileSystemObject") set?file?=?fso.CreateTextFile("D:RestartQTP.vbs") restartcode?=?"'浣跨?涓€涓??寰???翠娇寰?tp?借???c涓€涓??琛?????缁??"&vbnewline restartcode?=?restartcode?&"WScript.Sleep?3000"&vbnewline restartcode?=?restartcode?&"'浣跨?AOM?ユ???tp??????浣?"&vbnewline restartcode?=?restartcode?&"Dim?qtp"&vbnewline restartcode?=?restartcode?&"Set?qtp?=?CreateObject(""QuickTest.Application"")"&vbnewline restartcode?=?restartcode?&"qtp.Quit"&vbnewline restartcode?=?restartcode?&"WScript.sleep?2000"&vbnewline restartcode?=?restartcode?&"qtp.Launch"&vbnewline restartcode?=?restartcode?&"qtp.visible?=?true"&vbnewline restartcode?=?restartcode?&"set?qtp?=?nothing"&vbnewline restartcode?=?restartcode?&"set?fso?=?CreateObject(""Scripting.FileSystemObject"")"&vbnewline restartcode?=?restartcode?&"fso.deletefile?""D:RestartQTP.vbs"""&vbnewline restartcode?=?restartcode?&"set?fso?=?nothing"&vbnewline file.write?restartcode set?fso?=?nothing set?WshShell?=?CreateObject("WScript.Shell") WshShell.run?"cmd.exe?/c?D:RestartQTP.vbs" set?WshShell?=?nothing?

  这样可以实现重新启动QTP了,不过在执行下一个test之前需要一个等待时间,这个在调用脚本中很简单,不罗嗦了 



qtp vbs

需要 登录 后方可回复, 如果你还没有账号请 注册新账号