Command line 从maven/Jenkins运行Quicktest Pro测试?
我需要利用我们Maven/Jenkins构建的Quicktest Pro。我知道,我知道QTP不是最好的工具(我被“燃烧的狗屎袋”逗乐了),但我们的QE团队正在使用它,我想在詹金斯进行一些测试 1A。有人用过这种特殊的组合吗?一个示例/maven插件就好了 既然我怀疑这是可能的,让我们把它分成几部分 2A。如何从命令行简单地启动QTP测试?我想我可以用antrun或类似的东西来计算其他的启动部分 2B。QTP的结果格式似乎不像surefire报告那样是标准格式(我也不太清楚,所以我可能错了)。你能给我一些关于将报告结果返回给maven/Jenkins的指导吗?我认为这可能需要解析QTP结果文件。可以编写AOM(自动化对象模型)vbscript来调用QTP并运行特定测试。 这样的vbscript可以从Windows中的命令行运行 如果您可以从Maven/Jenkins运行/调用vbscript文件,那么通过命令行运行QTP脚本绝对是可能的 下面是触发QTP运行的示例AOM vbscript函数Command line 从maven/Jenkins运行Quicktest Pro测试?,command-line,maven,jenkins,qtp,Command Line,Maven,Jenkins,Qtp,我需要利用我们Maven/Jenkins构建的Quicktest Pro。我知道,我知道QTP不是最好的工具(我被“燃烧的狗屎袋”逗乐了),但我们的QE团队正在使用它,我想在詹金斯进行一些测试 1A。有人用过这种特殊的组合吗?一个示例/maven插件就好了 既然我怀疑这是可能的,让我们把它分成几部分 2A。如何从命令行简单地启动QTP测试?我想我可以用antrun或类似的东西来计算其他的启动部分 2B。QTP的结果格式似乎不像surefire报告那样是标准格式(我也不太清楚,所以我可能错了)。你
Public Function RunQTP(byVal strQC_Or_Local, byVal strTestPath, byVal strTestName, byVal strResultsFolder, byVal strTraceFile)', byVal strStore)
' Create the Application object
Dim objQTPApp,objQTPLibraries,objTestResults 'QTP
Dim strTempResultsRootFolder
strTempResultsRootFolder = "C:\TempTest\"
On Error Resume Next
'Loop for a minute or until qtp is successfully opened
StartTime = Now
Do
'Create QTP object
Set objQTPApp = CreateObject("QuickTest.Application")
'Clear any existing error numbers
Err.Clear
'If QTP is already launched, do nothing, else launch it
If objQTPApp.Launched = False Then
objQTPApp.Launch
End If
'Set qtp to visible
objQTPApp.Visible = True
'See if launching QTP has caused an error
intErr = Err.Number
'If it QTP has opened fine, exit the loop
If intErr = 0 Then
objQTPTraceFile.Write Now & " QTP open with no errors" & vbCR
Exit Do
'If there's an error, Close and QTP processes running (if any) and try again
Else
msgbox "Error in opening QTP"
End If
Loop Until DateDiff("s", StartTime, Now) > 180
On Error GoTo 0
objQTPApp.Options.Run.RunMode = "Fast"
If strQC_Or_Local = "QC" Then
'Connect To QC
strQCUsername = "Quality center username"
strQCPassword = "Quality center password"
If objQTPApp.TDConnection.IsConnected Then
'If QTP is already connected, if login details are different, then log out and log in again with given details
If objQTPApp.TDConnection.User <> strQCUsername Or objQTPApp.TDConnection.Domain <> strQCDomain Or _
objQTPApp.TDConnection.Project <> strQCProject Or objQTPApp.TDConnection.Server <> strQCPath Then
msgbox "connected as someone else - disconnecting, and then will reconnect"
objQTPApp.TDConnection.Disconnect
On Error Resume Next
objQTPApp.TDConnection.Connect strQCPath, strQCDomain, strQCProject, strQCUsername, strQCPassword, False
On Error GoTo 0
End If
Else
'If it's not already connected, log in with given details
On Error Resume Next
objQTPApp.TDConnection.Connect strQCPath, strQCDomain, strQCProject, strQCUsername, strQCPassword, False
On Error GoTo 0
End If
'If connected, tests in QC have [QualityCenter] appended before their name
If objQTPApp.TDConnection.IsConnected Then ' If connection is successful
strTestPath = "[QualityCenter] " & strTestPath
Else
MsgBox "Cannot connect to Quality Center" ' If connection is not successful, display an error message.
Exit Function
End If
End If
'Open the test
On Error Resume Next
objQTPApp.Open strTestPath, False
intErr = err.number
strErrDesc = err.description
On Error Goto 0
'If no problems
If intErr = 0 Then
'Configure the QTP settings
'Stop the test when an error occours
objQTPApp.Test.Settings.Run.OnError = "NextIteration"
'Select the Range you wish to run
objQTPApp.Test.Settings.Run.IterationMode = "oneIteration"
'Set sync timeout to be 20 seconds and disable smart identification
'objQTPApp.Test.Settings.Run.ObjectSyncTimeOut = 20000
objQTPApp.Test.Settings.Run.DisableSmartIdentification = True
'Ensure that the recovery mechanism is set to be activated for every step
'qtTestRecovery.SetActivationMode "OnError"
Set objTestResults = CreateObject("QuickTest.RunResultsOptions")
'If results folder path is empty, just save tests results to usual temp place
Dim blnSaveSpecificLocation
If strResultsFolder = "" Then
blnSaveSpecificLocation = False
objTestResults.ResultsLocation = "<TempLocation>"
Else
'Otherwise, save results to a temporary location, and then move the tests results to desired location before closing the test/stopping QTP etc
'Need to save to a temp location and then move, as it looks like that when another test is run, QTP deletes the previous set of results.
blnSaveSpecificLocation = True
'Create the results object
strDate = CStr(Now)
strDate = Replace(strDate, "/", "")
strDate = Replace(strDate, ":", ".")
strTestNameAppendage = strTestName & " " & objQTPApp.Test.Environment.Value("LocalHostName") & " " & strDate
strResults = strResultsFolder & "\" '& strTestNameAppendage
strTempResultsLocation = strTempResultsRootFolder & strTestNameAppendage
objTestResults.ResultsLocation = strTempResultsLocation
End If
objQTPTraceFile.Write Now & " Start Test" & vbCrLf
'If QTP crashes, it will be forced shut by 'KillQTP' after an hour. If this happens, 'objQTPApp.Test.Run objTestResults' will return an error
'so need to turn off error reporting and capture the error given if this is the case
On Error Resume Next
Dim intQTPErr
Err.Clear
'Run the test *************************** This is the line which triggers the QTP run
objQTPApp.Test.Run objTestResults
intQTPErr = Err.Number
On Error GoTo 0
objQTPTraceFile.Write Now & " End Test" & vbCrLf
Else
objQTPTraceFile.Write Now & " " & strTestPath & " could not be opened. Error message = " & strErrDesc & vbCRLf
End if
'Close Qtp
objQTPTraceFile.Write Now & " Just before checking the error number. Error Number was: " & intQTPErr & vbCRLf
On Error Resume Next
'If QTP has crashed, the number captured in intQTPErr will be -2147023170
If intQTPErr = "-2147023170" Then 'if it's crashed (could put <> 0 instead)
objQTPTraceFile.Write Now & " QTP Run Crashed or didn't finish in the time limit. Error Number was: " & intQTPErr & vbCRLf
Else
objQTPTraceFile.Write Now & " QTP Thinks it finished - stopping test: " & Err.Number & vbCRLf
'Close the test
objQTPApp.Test.Stop
objQTPTraceFile.Write Now & " QTP Thinks it stopped fine - closing test: " & Err.Number & vbCRLf
'Move the test from temp location to desired location
If blnSaveSpecificLocation = True Then
Call MoveFolder(strTempResultsLocation, strResults)
'objQTPApp.Test.Close
objQTPTraceFile.Write Now & " QTP Thinks it closed fine - error number is: " & Err.Number & vbCRLf
End If
objQTPTraceFile.Write Now & " QTP Process should have been killed" & vbCRLf
End If
On Error GoTo 0
'Set objects used to nothing
Set objQTPTraceFile = Nothing
Set fso = Nothing
Set qtTestRecovery = Nothing ' Release the Recovery object
Set objTestResults = Nothing
Set objQTPLibraries = Nothing
Set objQTPApp = Nothing
End Function
Public Function RunQTP(byVal strQC_或_Local,byVal strTestPath,byVal strTestName,byVal strResultsFolder,byVal strTraceFile)”,byVal strStore)
'创建应用程序对象
Dim objQTPApp、objQTPLibraries、objTestResults的QTP
Dim strTempResultsRootFolder
strTempResultsRootFolder=“C:\test\”
出错时继续下一步
'循环一分钟或直到成功打开qtp
开始时间=现在
做
'创建QTP对象
设置objQTPApp=CreateObject(“QuickTest.Application”)
'清除任何现有的错误号
呃,明白了
'如果QTP已启动,则不执行任何操作,否则将启动它
如果objQTPApp.Launched=False,则
objQTPApp.启动
如果结束
'将qtp设置为可见
objqtpap.Visible=True
'查看启动QTP是否导致错误
intErr=错误编号
'如果QTP打开良好,则退出循环
如果intErr=0,则
objQTPTraceFile.Write Now&“QTP打开时无错误”&vbCR
退出Do
'如果出现错误,请关闭正在运行的QTP进程(如果有),然后重试
其他的
msgbox“打开QTP时出错”
如果结束
循环到DateDiff(“s”,开始时间,现在)>180
错误转到0
objqtpap.Options.Run.RunMode=“快速”
如果strQC_或_Local=“QC”,则
'连接到QC
strQCUsername=“质量中心用户名”
strQCPassword=“质量中心密码”
如果objQTPApp.TDConnection.IsConnected,则
'如果QTP已连接,如果登录详细信息不同,则注销并使用给定的详细信息再次登录
如果objQTPApp.TDConnection.User strQCUsername或objQTPApp.TDConnection.Domain strQCDomain或_
objqtpap.TDConnection.Project strQCProject或objqtpap.TDConnection.Server strQCPath然后
msgbox“以其他人的身份连接-断开连接,然后将重新连接”
objQTPApp.TDConnection.Disconnect断开
出错时继续下一步
objqtpap.TDConnection.Connect strQCPath,strQCDomain,strQCProject,strqcustomer,strQCPassword,False
错误转到0
如果结束
其他的
'如果尚未连接,请使用给定的详细信息登录
出错时继续下一步
objqtpap.TDConnection.Connect strQCPath,strQCDomain,strQCProject,strqcustomer,strQCPassword,False
错误转到0
如果结束
'如果已连接,QC中的测试将在其名称之前附加[QualityCenter]
如果objqtpap.TDConnection.IsConnected,则“如果连接成功
strTestPath=“[QualityCenter]”和strTestPath
其他的
MsgBox“无法连接到质量中心”’如果连接不成功,则显示错误消息。
退出功能
如果结束
如果结束
“打开测试
出错时继续下一步
objqtpap.openstrtestpath,False
intErr=错误号
strErrDesc=err.description
错误转到0
"如果没有问题,
如果intErr=0,则
'配置QTP设置
'发生错误时停止测试
objqtpap.Test.Settings.Run.OnError=“NextIteration”
'选择要运行的范围
objqtpap.Test.Settings.Run.IterationMode=“oneIteration”
'将同步超时设置为20秒并禁用智能识别
'objQTPApp.Test.Settings.Run.ObjectSyncTimeOut=20000
objQTPApp.Test.Settings.Run.DisableSmartIdentification=True
'确保每个步骤都将恢复机制设置为激活
'qtTestRecovery.SetActivationMode“OnError”
Set-objTestResults=CreateObject(“QuickTest.RunResultsOptions”)
'如果结果文件夹路径为空,只需将测试结果保存到通常的临时位置即可
模糊BLNSAVESSpecification
如果strResultsFolder=“”,则
blnsavesspecification=False
objTestResults.ResultsLocation=“”
其他的
'否则,将结果保存到临时位置,然后在关闭测试/停止QTP等之前将测试结果移动到所需位置
'需要保存到临时位置,然后移动,因为在运行另一个测试时,QTP会删除以前的结果集。
BLNSAVESSpecification=True
'创建结果对象
标准日期=CStr(现在)
标准日期=替换(标准日期,“/”