从 Maven/Jenkins 运行 Quicktest Pro 测试?

发布于 2024-12-05 08:51:12 字数 485 浏览 1 评论 0原文

我需要利用 Maven/Jenkins 构建中的 Quicktest Pro。我知道,我知道 QTP 不是最好的工具(我对“一袋火红的狗便便”感到好笑 参考),但我们的 QE 团队正在使用它,我想在 Jenkins 中运行他们的一些测试。

1A。有人用过这个特定的组合吗?一个示例/maven 插件会很棒。

因为我怀疑这可能,所以让我们把它分成几部分。

2A。如何从命令行简单地启动 QTP 测试?我想我可以使用 antrun 或类似的东西来计算出其余的启动部分。

2B。 QTP 的结果格式似乎不像 Surefire 报告那样是标准的(我也不太了解,所以我可能是错的)。您能给我一些关于将报告结果返回到 Maven/Jenkins 的指导吗?我认为这可能涉及解析 QTP 结果文件。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放低过去 2024-12-12 08:51:12

可以编写 AOM(自动化对象模型)vbscript 来调用 QTP 并运行特定测试。
这样的 vbscript 可以在 Windows 中从命令行运行。

如果您可以从 Maven/Jenkins 运行/调用 vbscript 文件,那么绝对可以通过命令行运行 QTP 脚本。

下面是触发 QTP 运行的示例 AOM vbscript 函数

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文