0
我已經集成了Jenkins和QTP 10.0。我能夠從Jenkins運行我的測試腳本。我唯一遇到的問題是QTP輸出結果不顯示在Jenkins控制檯上。下面是VB腳本我寫道:Jenkins和QTP 10.0集成
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
你是如何執行這個腳本?你選擇了哪個構建任務? –