问题描述
我需要从我们的Maven / Jenkins构建中利用Quicktest Pro。我知道,我知道QTP不是最好的工具在那里(我很高兴的火焰狗poo袋),但我们的QE团队正在使用它,我想在Jenkins中运行一些测试。
1A。有没有人使用这种特定的组合?
因为我怀疑这是可能的,所以让它分成几块。
。你如何简单地从命令行启动QTP测试?我想我可以使用antrun或类似的东西来计算其余部分的启动部分。
2B。 QTP的结果格式似乎不像是肯定的报告(我不知道,所以我可能是错误的标准)。你能给我一些指导将报告结果回到maven / Jenkins吗?我认为可能涉及解析QTP结果文件。
调用QTP并运行特定测试。
这样的vbscript可以从Windows中的命令行运行。
如果你可以从Maven / Jenkins运行/调用vbscript文件, QTP脚本通过命令行。
一个用于触发QTP运行的示例AOM vbscript函数如下
公共函数RunQTP(byVal strQC_Or_Local,byVal strTestPath,byVal strTestName,byVal strResultsFolder,byVal strTraceFile)',byVal strStore)
'创建应用程序对象
Dim objQTPApp,objQTPLibraries,objTestResults'QTP
Dim strTempResultsRootFolder
strTempResultsRootFolder =C:\TempTest\
在错误恢复下
'循环一分钟或直到qtp成功打开
StartTime =现在
Do
'创建QTP对象
设置objQTPApp = CreateObject(QuickTest.Application)
'清除任何现有的错误号
Err.Clear
'如果QTP已经启动,不执行任何操作,否则启动它
如果objQTPApp.Launched = False然后
objQTPApp.Launch
End If
'将qtp设置为visible
objQTPApp.Visible = True
'查看启动QTP是否导致错误
intErr = Err.Number
如果QTP已打开,退出循环
如果intErr = 0然后
objQTPTraceFile.Write Now& QTP打开没有错误& vbCR
退出Do
'如果有错误,关闭和QTP进程运行(如果有),然后重试
Else
msgbox打开QTP时出错
End If
循环直到DateDiff(s,StartTime,Now)> 180
错误GoTo 0
objQTPApp.Options.Run.RunMode =Fast
如果strQC_Or_Local =QC然后
'连接到QC
strQCUsername =质量中心用户名
strQCPassword =质量中心密码
$ b b如果objQTPApp.TDConnection.IsConnected然后
'如果QTP已经连接,如果登录详细信息不同,则注销并重新登录给定的详细信息
如果objQTPApp.TDConnection.User<> strQCUsername或objQTPApp.TDConnection.Domain<> strQCDomain或_
objQTPApp.TDConnection.Project<> strQCProject或objQTPApp.TDConnection.Server<> strQCPath然后
msgbox连接作为别人 - 断开,然后将重新连接
objQTPApp.TDConnection.Disconnect
On Error Resume Next
objQTPApp.TDConnection.Connect strQCPath,strQCDomain, strQCProject,strQCUsername,strQCPassword,False
出现错误GoTo 0
结束如果
否则
'如果尚未连接,请使用给定的详细信息登录
On Error Resume Next
objQTPApp.TDConnection.Connect strQCPath,strQCDomain,strQCProject,strQCUsername,strQCPassword,False
出错时转到0
结束如果
'如果连接,QC中的测试有[QualityCenter]在它们的名字之前
如果objQTPApp.TDConnection.IsConnected那么'如果连接成功
strTestPath =[QualityCenter]& strTestPath
Else
MsgBox无法连接到Quality Center'如果连接失败,则显示错误消息。
退出函数
结束如果
结束如果
'打开测试
错误恢复下一个
objQTPApp.Open strTestPath,False
intErr = err.number
strErrDesc = err.description
错误转到0
'如果没有问题
如果intErr = 0然后
'配置QTP设置
当错误发生时停止测试
objQTPApp.Test.Settings.Run.OnError =NextIteration
'选择要运行的范围
objQTPApp.Test.Settings.Run.IterationMode =oneIteration
'将同步超时设置为20秒,并禁用智能识别
'objQTPApp.Test.Settings.Run.ObjectSyncTimeOut = 20000
objQTPApp.Test.Settings.Run.DisableSmartIdentification = True
'确保将恢复机制设置为为每个步骤激活
'qtTestRecovery.SetActivationModeOnError
设置objTestResults = CreateObject(QuickTest.RunResultsOptions)
'如果结果文件夹路径为空,只需将测试结果保存到通常的临时位置
Dim blnSaveSpecificLocation
如果strResultsFolder =然后
blnSaveSpecificLocation = False
objTestResults.ResultsLocation =< ; TempLocation>
否则
'否则,将结果保存到临时位置,然后将测试结果移动到所需位置,然后关闭测试/停止QTP等
'需要保存到临时位置,然后移动,因为它看起来像当运行另一个测试时,QTP删除以前的结果集。
blnSaveSpecificLocation = True
'创建结果对象
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
如果
结束objQTPTraceFile.Write现在& 开始测试& vbCrLf
'如果QTP崩溃,它将被KillQTP在一个小时后强制关闭。如果发生这种情况,'objQTPApp.Test.Run objTestResults'将返回一个错误
'所以需要关闭错误报告并捕获错误给出,如果这种情况
在错误恢复下一步
Dim intQTPErr
Err.Clear
'运行测试***************************这是触发QTP运行的行
objQTPApp.Test.Run objTestResults
intQTPErr = Err.Number
错误GoTo 0
objQTPTraceFile.Write现在& 结束测试& vbCrLf
Else
objQTPTraceFile.Write Now& & strTestPath& 无法打开。错误消息=& strErrDesc& vbCRLf
如果
结束
结束Qtp
objQTPTraceFile.Write现在& 就在检查错误号之前。错误号是:& intQTPErr& vbCRLf
在错误恢复下
'如果QTP崩溃,在intQTPErr捕获的数字将是-2147023170
如果intQTPErr =-2147023170然后'如果它崩溃put<> 0)
objQTPTraceFile.Write现在& QTP运行崩溃或没有在时间限制内完成。错误号码是:& intQTPErr& vbCRLf
Else
objQTPTraceFile.Write Now& QTP认为它完成了 - 停止测试:&错误编号& vbCRLf
'关闭测试
objQTPApp.Test.Stop
objQTPTraceFile.Write现在& QTP认为它停止了 - 关闭测试:&错误编号& vbCRLf
将测试从临时位置移动到所需位置
如果blnSaveSpecificLocation = True然后
调用MoveFolder(strTempResultsLocation,strResults)
'objQTPApp.Test.Close
objQTPTraceFile.Write Now& QTP认为它关闭了 - 错误号是:&错误编号& vbCRLf
结束如果
objQTPTraceFile.Write现在& QTP过程应该被杀死& vbCRLf
结束如果
出现错误GoTo 0
'设置无对象的对象
Set objQTPTraceFile = Nothing
Set fso = Nothing
设置qtTestRecovery = Nothing'释放恢复对象
设置objTestResults =无
设置objQTPLibraries =无
设置objQTPApp =无
结束函数
I need to leverage Quicktest Pro from our Maven/Jenkins builds. I know, I know QTP is not the best tool out there (I'm amused by the "bag of flaming dog poo" reference), but our QE team is using it and I want to run some of their tests in Jenkins.
1A. Has anyone used this specific combination? An example/maven plugin would be great.
Since I doubt that is likely, lets break it up into pieces.
2A. How do you simply launch a QTP test from the command line? I think I can figure the rest of the launching part of things out using antrun or something like that.
2B. The results format from QTP doesn't appear to be a standard like surefire reports (I don't know either well, so I might be wrong). Can you give me some guidance on getting report results back into maven/Jenkins? I'm thinking that may involve parsing the QTP results file.
An AOM ( Automation Object Model ) vbscript could be written to invoke QTP and run a specific test.Such a vbscript could be run from command line in Windows.
If you can run/invoke vbscript files from Maven/Jenkins , it is definitely possible to run QTP scripts through command line.
A sample AOM vbscript function to trigger QTP run is below
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
这篇关于从maven / Jenkins运行Quicktest Pro测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!