多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

在QTP Test中利用vbs和cmd实现重新启动QTP-自动化测试

更新时间:2022-05-12 09:27:21 作者:多测师 浏览:206

  连续长时间执行过QTP或使用QC连续长时间调用QTP的朋友应该会知道,QTP在长时间执行过程中会产生内存泄露。而QTP自身也有一个工具Remote Agent来实现每执行N次来重新启动测试工具释放内存。

在QTP Test中利用vbs和cmd实现重新启动QTP-自动化测试

  但是,不知道是不是我用破解版的原因,如果使用RunTest来调用QC执行QTP时,这个设置的Remote Agent会使得测试失败,并卡死在某一步。所以在这里需要进行手动清理QTP长时间运行过程中产生的内存泄露。

  在这里,我所知的清理内存有两种方式,一种是利用一些内存清理工具,一种是通过脚本控制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 Test中利用vbs和cmd实现重新启动QTP,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部