0

As a project requirement, We are doing webservice testing using soapui pro . I have already created a batch file to execute the test case from soap ui. Now, as porject testcases are increasing, we would like to run our soapui testcases from Quality center.

Please note, our client doesn't want to invest on license. I would appreciate it , if someone can help me with steps and also if possible with require code.

user2626534
  • 11
  • 1
  • 1

1 Answers1

1

I was able to build a framework for just this purpose. Creating a Vapi-XP test in QC that invokes a VBScript based framework you can build this out from scratch in about 3-4 days.

All in all a couple hundred lines of code.

explaination of code @ http://ryanoglesby.net/2013/08/30/executing-soapui-from-quality-center-part-3-the-final-chapter-framework/

QC Script:

'*****************************************************************************
' Call to include our external FW script and execute the primary
' function "SoapUI"
'*****************************************************************************
Sub Test_Main(Debug, CurrentTestSet, CurrentTSTest, CurrentRun)
'include the framework VBScript
Include "C:\FW_SoapUI.vbs"
'Call the primary ("renamed Main") function
SoapUI TDOutput, Debug, CurrentTestSet, CurrentTest, CurrentRun, ThisTest
End Sub

'*****************************************************************************
' include VBScript file and allow Subs and functions to be executed
'*****************************************************************************
Sub Include(file)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(file, 1)
str = f.ReadAll
f.Close
ExecuteGlobal str
End Sub

VB Framework

'**************************************************************************
' Declare test properties
' Thes properties will be read from QC Attachment *.properties
'**************************************************************************
dim rptDir
dim prjDir
dim trPath
dim prjName
dim tSuite
dim tCase
'**************************************************************************
'Debug, CurrentTestSet, CurrentTest, CurrentRun
'Debug, CurrentTestSet, CurrentTSTest, CurrentRun
'**************************************************************************
Sub SoapUI(TDOutput, Debug, CurrentTestSet, CurrentTest, CurrentRun, ThisTest)
' *** VBScript Limitation ! ***
' "On Error Resume Next" statement suppresses run-time script errors.
' To handle run-time error in a right way, you need to put "If Err.Number <> 0 Then"
' after each line of code that can cause such a run-time error.

On Error Resume Next
'Clear output window
TDOutput.Clear

'**************************************************************************
' Define the path for SOAPUI executable bat file and Project xml
' Project xml contains the test case(s) that need to be executed
'**************************************************************************
Dim testRunnerPath 'Path to test runner bat file
Dim soapResults 'Result file generated by SoapUI Groovy Script
Dim projFP 'SoapUI Project File Path
Dim spath 'Result File - Currently not using
Dim tf 'Test Factory Object
Dim ts 'Test ID
Dim TestSuite 'SoapUI Test Suite Name
Dim TestCase 'SoapUI Test Case Name
Dim resultsP 'SoapUI output Report Location - Currently Not using

'Read test properties from attached file
readPropertiesfile
'TDOutput.Print rptDir
'TDOutput.Print prjDir
'TDOutput.Print trPath
'TDOutput.Print prjName
TDOutput.Print tSuite
TDOutput.Print tCase

projFP = prjDir & prjName
spath = "C:\00_soapuicmdexecute.txt"
testRunnerPath = trPath & "testrunner.bat"

'Strings for SoapUI Execution
TestSuite=tSuite
TestCase=tCase
resultsP="C:\SoapResults\Test\" & TestCase
soapResults = rptDir & TestCase & ".txt"

Set tf = TDConnection.TestFactory

Set ts = tf.Item(Field("TS_TEST_ID"))

'**************************************************************************
' Invoke SOAPUI and execute the selected project
'**************************************************************************

invokeSOAPUIClient testRunnerPath, projFP, TestSuite, TestCase, resultsP, CurrentTest, CurrentRun

'**************************************************************************
' Get the Results from the text file in to Run Steps of the test case
'**************************************************************************

'wait 1 second to allow for larger files to complete writing
TDOutput.Print "Start Wait 1"
XTools.Sleep 1000
TDOutput.Print "END Wait 1"

'Get Result file and write to run steps
getResultsToQC CurrentRun, soapResults

'**************************************************************************
' handle run-time errors
'**************************************************************************
If Not Debug Then
If Err.Number <> 0 Then
TDOutput.Print "Run-time error - Execute SOAPUI:Enter SuB - [" & Err.Number & "] : " & Err.Description
CurrentRun.Status = "Failed"
CurrentTest.Status = "Failed"
Else
CurrentRun.Status = "Passed" 'Need Function here to determine if all steps passed
CurrentTest.Status = "Passed" 'Need Function here to determine if all steps passed
End If
End If

End Sub

'**************************************************************************
' Sub for executing SOAPUI with the selected project
'**************************************************************************
' soapuiTestrunnerPath: TestRunner .bat file
' projectLocation: Project file location
'**************************************************************************

Sub invokeSOAPUIClient(soapuiTestrunnerPath, projectLocation, TSuite, Tcase, resultsP, CurrentTest, CurrentRun)
'**************************************************************************
' Execute SOAPUI from the command line
' Output Test Values for reference - Not Required
'**************************************************************************
TDOutput.Print "TSuite: " & TSuite
TDOutput.Print "Tcase: " & Tcase
TDOutput.Print "resultsP: " & resultsP

set fileSystem = CreateObject("Scripting.FileSystemObject")

'**************************************************************************
' Raise error if SOAPUI is not installed in the host where program is
' runned or if the path of executable bat file provided is not correct
'**************************************************************************

If ( not fileSystem.FileExists(soapuiTestrunnerPath)) then
Err.Raise 8
Err.Description = "soapUI testrunner not found: " + soapuiTestrunnerPath
End if

'**************************************************************************
'args will be the options that you wish to pass to the TestRunner
'for a full list of options call the test runner from the command prompt with
'no options
'**************************************************************************
Dim args
'args = "-s" & chr(34) & TSuite & chr(34) & " -c" & chr(34) & TCase & chr(34) & " -Drpath=" & resultsP & " -r -a -I "& chr(34) & projectLocation & chr(34) &""
args = "-s" & TSuite & " -c" & TCase & " -M -j -F XML -R test.xml -f " & resultsP & " -r -g -A -I "& chr(34) & projectLocation & chr(34) &""
XTools.run soapuiTestrunnerPath, args, -1, true

End Sub

'**************************************************************************
' Sub for Adding Results to QC - Parent to addRunData() function
' function will parse the result file generated by SoapUI Groovy Script &
' add the run details for the Soap UI test to the QC run
'**************************************************************************
' sFile: File path to Groovy Script Results "C:\Groovy_Report\test1.txt"
' Currently this value is HARD CODED
'**************************************************************************
sub getResultsToQC(CurrentRun, sFile)
Set objFS = CreateObject("Scripting.FileSystemObject")
'Create object for result file
Set objFile = objFS.GetFile(sFile)
'OPen Stream to read in file
Set ts = objFile.OpenAsTextStream(1,-2)
'Loop through file line by line
Do Until ts.AtEndOfStream
'Create string value for current line
strLine = ts.ReadLine
'TDOutput.Print strLine

'Split values based on delimiter (Set in groovy Script)
ArrSplit=Split(strLine, "|")
size = Ubound(ArrSplit)

'Determine action for array values
'Size = 6 is a report value that will have pass/fail
'Size <> 6 is a info value and will have status = N/A
if(size=6) Then
'StepName
sStepName = ArrSplit(1) & "-" & ArrSplit(2)

'Clean Step Status and determine pass/fail
sSplit = Split(ArrSplit(4),":")
sValue = Trim(sSplit(1))
if(sValue="VALID")Then
sStatus = "Passed"
Elseif (sValue="FAILED") then
sStatus = "Failed"
Else
sStatus = "N\A"
End If

'Step Description
sDescription = ArrSplit(5)

'Step Expected
sExpected = ArrSplit(3)

'Step Actual
sActual = Trim(ArrSplit(6))

Add run result to current execution run
addRunData CurrentRun, sStepName, sStatus, sDescription, sExpected, sActual
else
'Added in case other options arise in the future
if(Trim(ArrSplit(0)) = "INFO") Then
sStepName = "INFO - " & ArrSplit(1)
sStatus = "N/A"
sDescription = ArrSplit(1)
sExpected = "N/A"
sActual = ArrSplit(2)
addRunData CurrentRun, sStepName, sStatus, sDescription, sExpected, sActual
End If
End if

Loop
ts.Close
end sub

'**************************************************************************
' Sub for adding Test Steps to the current run
' function will add the run details for the Soap UI test to the QC run
'**************************************************************************
' sStepName: Passed from getResultsToQC - String to display the step name
' sStatus: Passed from getResultsToQC - String to determine step status
' sDescription: Passed from getResultsToQC - String to describe step
' sExpected: Passed from getResultsToQC - String to show expected value
' sActual: Passed from getResultsToQC - String to show actual value
'**************************************************************************

Sub addRunData(CurrentRun, sStepName, sStatus, sDescription, sExpected, sActual )

Dim objRun
Set objRun = CurrentRun
'Create Step object and add values to Object array
Set objStep = objRun.StepFactory.AddItem(null)
objStep.Field("ST_STEP_NAME")= sStepName
objStep.Field("ST_STATUS") = sStatus
objStep.Field("ST_DESCRIPTION") = sDescription
objStep.Field("ST_EXPECTED") = sExpected
objStep.Field("ST_ACTUAL") = sActual
objStep.Post
Set objStep = Nothing

end sub

'**************************************************************************
'Read in the attached property file
'Will assign global values based on Property names
'**************************************************************************
' atch: name of file attachment
'**************************************************************************
sub readFile(atch)
'Path to QC attachments
atch = "\\Server\Path\For\qc\project\file\attachments\" & atch
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.GetFile(atch)
Set tstream = objFile.OpenAsTextStream(1,-2)
Do Until tstream.AtEndOfStream
'read each line of the file
strLine = tstream.ReadLine
'**************************************************************************
'check if string begins with #
'Strings beginning with # are comments
'**************************************************************************
if Left(strLine,1) = "#" then
'Do Nothing
else
'When a valid string is found get property name
sName = parseName(strLine)
'When a valid string is found get property value
sValue = parseValue(strLine)
'Determine which global variable should be set
setGblValue sName,sValue
end if
Loop
tstream.Close

end sub

'**************************************************************************
' Set the global variables based upon the property name
' assign global variable values
'**************************************************************************
' sName: Property name
' sValue: Property Value
'**************************************************************************
sub setGblValue(sName,sValue)
Select Case (sName)
Case("rptDir")
rptDir = sValue
Case("projectDir")
prjDir = sValue
Case("trPath")
trPath = sValue
Case("project")
prjName = sValue
Case("testSuite")
tSuite = sValue
Case("testCase")
tCase = sValue
Case Else
TDOutPut.Print "[" & sName & "] is an unknown element and contains the value [" & sValue & "]"
End Select
end sub

'**************************************************************************
' From the given string parse out and return the property Name
' Returns Property Name
'**************************************************************************
' strLine: Current line of file being read
'**************************************************************************
function parseName(strLine)
sSplit = Split(strLine,"=")
sProperty = Trim(sSplit(0))
parseName = sProperty
end function

'**************************************************************************
' From the given string parse out and return the property Value
' Returns Property Value
'**************************************************************************
' strLine: Current line of file being read
'**************************************************************************
function parseValue(strLine)
sSplit = Split(strLine,"=")
sValue = Trim(sSplit(1))
'TDOutput.Print "PropertyValue: " & sValue
parseValue = sValue
end function

'**************************************************************************
' Process to get and read property file
' process looks for *.properties file attached to the current test
' returns file name and calls readFile
'**************************************************************************
sub readPropertiesfile()
' Use Test.Attachments to get the AttachmentFactory.
Set theTest = ThisTest
Set TestAttachFact = theTest.Attachments
Set AttachFilter = TestAttachFact.Filter
AttachmentName = Trim(AttachmentName)
Dim pos
pos = InStr(1, AttachmentName, "*")
If pos = 1 Then
AttachFilter.Filter("CR_REFERENCE") = AttachmentName
Else
AttachFilter.Filter("CR_REFERENCE") = "*" & AttachmentName
End If
Set attachList = TestAttachFact.NewList(AttachFilter.Text)
Dim minLength
minLength = 32000
For Each TAttach In attachList
With TAttach
'look for file that contains ".properties"
If instr(1,.Name,".properties") Then
Set theAttachment = TAttach
Else
Set theAttachment = nothing
End If
End With
Next

'Get Attachment Name
dim attachmentname
attachmentname = theAttachment.Name

readFile attachmentname
end sub

you'll still need the groovy script to handle your reporting

Roglesby
  • 59
  • 4