cancel
Showing results for 
Search instead for 
Did you mean: 

How do I log raw request and response messages to a file every time test case or suite is run?

Highlighted
Occasional Contributor

How do I log raw request and response messages to a file every time test case or suite is run?

Hi 

 

I would like to know how I can create a file that write all raw request and response messages to this every time a test case or suite is run?

 

Is this an inbuilt feature of Ready API or do I need to write an event handler?

 

Thanks.

2 REPLIES 2
Highlighted

Re: How do I log raw request and response messages to a file every time test case or suite is run?

You can use a DataSink Test Step to output requests/responses. For more information, see this document.

Amber
Highlighted
Occasional Contributor

Re: How do I log raw request and response messages to a file every time test case or suite is run?

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()

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors