Forum Discussion
You can use a DataSink Test Step to output requests/responses. For more information, see this document.
- tamnorOccasional Contributor
Thanks for that. I've also found that I can add a TestRunListener.afterStep event with the following code ...
//creates subfolder name from testCase name and dateTime Stamp
def subFolderName = testRunner.getTestCase().label.toString() + new Date().format("yyyy-MM-dd'T'HH.mm").toString()
//creates variable to store parentFoldername
def parentFolder = context.expand('${#Project#reqRespParentFolder}')//makes new directory out of parentFolder and subFolder name
new File(parentFolder+subFolderName).mkdir()//creates variable for subFolder path
def reqRespSubFolderPath = parentFolder+subFolderName+"/"//sets the subFolder path and subFolderName test case properties
testRunner.getTestCase().setPropertyValue('reqRespSubFolderPath',reqRespSubFolderPath)
testRunner.getTestCase().setPropertyValue('subFolderName',subFolderName)//creates new file in subFolder path with correct subFolderName
def requestResponseInputFile = new File(reqRespSubFolderPath + subFolderName + ".txt")//set property value for requestResponseInputFile to write to
testRunner.getTestCase().setPropertyValue('requestResponseInputFile',requestResponseInputFile.toString())
//From here//creates variable to store requestREsponseInputFile
def inputFileResponse = context.expand('${#TestCase#requestResponseInputFile}')//fos = new FileOutputStream( filePath + inputFileResponse.testStep.label + '.txt', true )
//creates file output stream and printWriter variables
fos = new FileOutputStream(inputFileResponse, true )
pw = new PrintWriter( fos )//if step has a response property write result to the file.
if(context.currentStep.hasProperty("Response"))
{
testStepResult.writeTo( pw )
}
pw.close()
fos.close()