Выполняете тесты Quicktest Pro от Maven / Jenkins? - PullRequest
4 голосов
/ 16 сентября 2011

Мне нужно использовать Quicktest Pro из наших сборок Maven / Jenkins. Я знаю, я знаю, что QTP не самый лучший инструмент (меня удивляет «мешок с пылающей собакой» ссылка ), но наша команда QE использует его, и я хочу запустить их тесты в Дженкинсе.

1A. Кто-нибудь использовал эту конкретную комбинацию? Плагин example / maven был бы великолепен.

Поскольку я сомневаюсь, что это вероятно, давайте разбить его на куски.

2A. Как вы просто запускаете тест QTP из командной строки? Я думаю, что могу понять остальную часть запуска, используя antrun или что-то в этом роде.

2B. Формат результатов из QTP, похоже, не является стандартом, подобным отчетам о достоверности (я тоже не очень хорошо знаю, поэтому могу ошибаться). Можете ли вы дать мне несколько советов о том, как вернуть результаты отчета в Maven / Jenkins? Я думаю, что это может быть связано с анализом файла результатов QTP.

1 Ответ

6 голосов
/ 20 сентября 2011

VOM-скрипт AOM (объектная модель автоматизации) может быть написан для вызова QTP и запуска определенного теста.Такой vbscript может быть запущен из командной строки в Windows.

Если вы можете запускать / вызывать файлы vbscript из Maven / Jenkins, безусловно, можно запускать сценарии QTP через командную строку.

AПример функции AOM vbscript для запуска QTP ниже

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
...