To save request and response in soapui using groovy -
A groovy event handler does saving request and response by a
script below which records the request and response for each test step. The
event handler is 'TestRunListener.AfterStep'
The script is as
def pName =
context.currentStep.testCase.testSuite.project.name //get project name
def pDate = new Date().format( 'yyyyMMdd' )//get current
date
def sDate = pDate.toString()//convert date to string
def pTestSuite =
context.currentStep.testCase.testSuite.name//get TestSuite name
def pTestCase = context.currentStep.testCase.name//get
TestCase name
def filePath = 'C:/SoapUI
Projects/TS0.1/TestEvidence/'+pName+'_'+sDate+'/'+pTestSuite+'/'+pTestCase+'/'//compose
the folder path
File file = new File(filePath)
if (!file.exists()) file.mkdirs()//create the destination
folder
fos = new FileOutputStream(filePath+
testStepResult.testStep.label + '.txt', true)
pw = new PrintWriter( fos )
testStepResult.writeTo( pw )
pw.close()
fos.close()