qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

让你的自动化测试更加“自动化”

 前段时间,老板要求每天包括晚上要在不同的压力下,且不断重复地运行smoke test.但是晚上我们不可能就自己动手让我们的QTP的运行,而且就算是白天也不可能做到在某一个时间点上,自己手动来运行自动化测试
  那该怎么办呢?可以考虑用Window自带的Schedule来定时触发我们的QTP。但是schedule是无法直接去打开QTP或者去运行VBS,那又该怎么办?我是用下的解决方法与大家共享:
  Schedule -> Bat -> VBS -> QTP主函数 -> VBScripts.具体代码如下:
  Bat:
  ------------------------------------
taskkill /im  EXCEL.EXE /f
taskkill /im  wscript.exe /f
taskkill /im  QTPro.exe /f
taskkill /im  QTAutomationAgent.exe /f
ping -n 3 127.1>nul
start C:\AutoTest\TA_AutomationTest\C955\3_QTPScript\0_MainScript\LaunchLoopTest.vbs
****************************************************************************
  LaunchLoopTest.vbs:
  ----------------------
Dim qtApp
Dim qtTest
Dim qtResultsOpt
Dim GenerateDateTime,TestResult,BakTestResult
GenerateDateTime =Replace(FormatDateTime(Date(),2),"/","_") & "-" & Replace(FormatDateTime(Time(),3),":","_")   '自定义一个获取当前时间的字符串
TestResult = "C:\AutoTest\TA_AutomationTest\1_Report\ExcelReport\Test_Result.xls" '获得测试结果
BakTestResult  = "C:\AutoTest\TA_AutomationTest\1_Report\ExcelReport\Test_Result" & GenerateDateTime & ".xls"
Set qtApp = CreateObject("QuickTest.Application") ' 建立QTP的应用对象
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' 让QTP运行过程可见
' 设置当运行过程中如果出错,抓图。
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
' 快速运行。
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
qtApp.Open "C:\AutoTest\TA_AutomationTest\C955\3_QTPScript\0_MainScript\MainScript2", True ' 以只读的方式开打开QTP主函数
' 为Test设置运行
Set qtTest = qtApp.Test
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' 建立测试结果
qtResultsOpt.ResultsLocation = "C:\AutoTest\TA_AutomationTest\1_Report\" & GenerateDateTime ' 建立起QTP自动的测试结果路径
'qtResultsOpt.ResultsLocation = "D:\temp2\res1"
qtTest.Run qtResultsOpt ' 运行QTP主函数
qtTest.Close ' 关闭主函数
qtApp.Quit  ' 退出
Set qtResultsOpt = Nothing ' 释放对象
Set qtTest = Nothing
Set qtApp = Nothing
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile TestResult, BakTestResult   '备份当前运行完脚本后的测试结果
Set fso = Nothing

posted on 2014-01-09 10:42 顺其自然EVO 阅读(258) 评论(0)  编辑  收藏 所属分类: qtp


只有注册用户登录后才能发表评论。


网站导航:
 
<2014年1月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜