Jenkins和QTP 10.0集成

时间:2016-11-15 05:51:53

标签: jenkins qtp

我已经集成了Jenkins和QTP 10.0。我可以从Jenkins运行我的测试脚本。我面临的唯一问题是Jenkins控制台上没有显示QTP输出结果。下面是我写的VB脚本:

Dim App,strDrive, strfoldername,objFSO, objFolder, strPath, TestScriptpath1, oFSO


' Launch QuickTest Professional and make it visible.
Set App = CreateObject("QuickTest.Application")
Set qtResultsObj = CreateObject("QuickTest.RunResultsOptions")
Set fsobj=CreateObject("Scripting.FileSystemObject")
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.WorkBooks.Open("C:\Batch File\QTP_Scripts.xls")
Set xlSheet = xlBook.WorkSheets("Sheet1")
'Set stdout = fsobj.GetStandardStream (1)
'stdout.WriteLine "This will go to standard output."

Set WshShell = CreateObject("WScript.Shell")


App.Launch
App.Visible = True
strfoldername="_Result"

'Read all the Test path from the Excel and Loop through all the tests.
For ix = 2 To xlSheet.UsedRange.Rows.Count
    TestScriptpath = xlSheet.Cells(ix, 1).value
    TestScriptpath1=Split(TestScriptpath, "\")

    'Open the test in QuickTest Professional.
    App.Open TestScriptpath,True,False


    'Create Environment Variables to pass the results from QTP to runner.vbs
    APP.Test.Environment.Value("JenkinsFlag") = "Y"
    APP.Test.Environment.Value("JenkinsTestCaseDescription") = TestScriptpath1(2)


    sResultFolderPath="C:\BUILD_TAG\"
    '' Get the test object.
    Set qtTest = App.Test
    ResultFolderPath1=sResultFolderPath&TestScriptpath1(2)&strfoldername
    Set objFolder = fsobj.CreateFolder(sResultFolderPath1)

    'Execute the test. Instruct QuickTest Professional to wait for the test to finish executing.
    'This statement specifies a test results location.
    qtResultsObj.ResultsLocation=sResultFolderPath1
    qtTest.Run qtResultsObj, True 
    StrResult=qtTest.LastRunResults.Status
    xlSheet.Cells(ix, 2).value=StrResult


    'Write the result in the console
    While APP.Test.isRunning
        If APP.Test.Environment.Value("JenkinsFlag") = "Y" Then
            'APP.Test.Environment.Value("JenkinsFlag") = "N"

            ' Show TC ID and Description
            WshShell.StdOut.WriteLine  APP.Test.Environment.Value("JenkinsTestCaseDescription")&TestScriptpath1(2)
            'stdout.WriteLine APP.Test.Environment.Value("JenkinsTestCaseDescription") &TestScriptpath1(2)


            'Wait till the test is executed & result is updated
            While (APP.Test.Environment.Value("JenkinsTestCaseResult") = Reporter.runstatus AND APP.Test.isRunning)
               WshShell.Sleep 1000
               'stdout.Sleep 1000
            Wend

            'Show the Result
            WshShell.StdOut.Write APP.Test.Environment.Value("JenkinsTestCaseResult")
            'stdout.Write APP.Test.Environment.Value("Jenkins TestCaseResult")
        End If
        WshShell.Sleep 1000
        'stdout.Sleep 1000
    Wend

    ' Close the test.
    qtTest.Close 
Next
xlApp.ActiveWorkbook.Save
xlApp.ActiveWorkbook.Close

App.Quit
xlApp.Quit

If Not xlApp Is Nothing Then
    xlApp.Quit
    Set xlApp = Nothing
End If

'Release the created objects.
set qtResultsObj = nothing
set fsobj= nothing
set qtTest = nothing
set App = nothing 
set xlApp = nothing
set xlBook = nothing
set xlSheet= nothing

1 个答案:

答案 0 :(得分:0)

我创建了一个样本运行器文件,它将执行测试,在控制台中显示结果&创建一个简单的HTML文件。

点击此处了解详情:

http://www.testautomationguru.com/qtpuft-jenkins-github-svn-integration/

源代码:

https://github.com/vinsguru/tag-qtp-jenkins-demo