Department_of_T
12 years agoContributor
Write XML response to a file
Hi, I have the following groovy code which successfully writes the response files to disk but it always writes at least 2 copies of the request and 2 of the response instead of just one. Can anyone advise on how to only save the request/response once?
Using responseFile.write(response) or responseFile.println(response) does not make a difference.
OUTPUT of just clicking the PLAY button to test the groovy script.
09-01-37-475 findPersonChangeCustomerDetails - XML [request_row8 ](subsequent_given_names Invalid Format)
09-01-37-481 findPersonChangeCustomerDetails - XML [RESPONSE_row8 ](subsequent_given_names Invalid Format)
09-01-37-482 findPersonChangeCustomerDetails - XML [request_row8 ](subsequent_given_names Invalid Format)
09-01-37-488 findPersonChangeCustomerDetails - XML [RESPONSE_row8 ](subsequent_given_names Invalid Format)
note: I need the timestamp in milliseconds so i can sort the files nicely in Windows Explorer by name (otherwise there can be 2 or 3 requests sent in 1 sec which show up out of order when sorting the files)
Using responseFile.write(response) or responseFile.println(response) does not make a difference.
groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def name = context.getCurrentStep().getLabel()
def testSuiteLongName = messageExchange.modelItem.testStep.testCase.testSuite.name
def testCaseLongName = messageExchange.modelItem.testCase.name
def testSuite = testSuiteLongName.replace("TestSuite: ", "")
def testCase = testCaseLongName.replace("TestCase: ", "")
def testStep = messageExchange.modelItem.testStep.name
def directory = "C:/SoapOutput/" + date() + "/" + testSuite+ "/" + testCase
def failedDirectory = "C:/SoapOutput/" + date() + "/" + testSuite+ "/" + testCase + "/Failures"
new File(directory).mkdirs()
def row = messageExchange.modelItem.testCase.testSteps["FindPersonValidations DataSource"].currentRow
def inputRowNo = messageExchange.modelItem.testCase.testSuite.getPropertyValue("input")
def inputReasonCode = messageExchange.modelItem.testCase.testSuite.getPropertyValue("reasoncode")
def time() {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('HH-mm-ss-SSS')
shortDateName = dateFormat.format(date)
return shortDateName
}
def date() {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('ddMMyyyy')
shortDateName = dateFormat.format(date)
return shortDateName
}
//Save Request File
def requestFile = new PrintWriter ( directory +"/"+time()+" "+ name + " [request_row"+inputRowNo+" ]("+ inputReasonCode + ").xml")
def request = context.expand( '${'+ name + '#Request}' )
requestFile.println(request)
requestFile.flush()
requestFile.close()
//Save Response File
def responseFile = new PrintWriter (directory +"/"+ time()+" "+ name +" [RESPONSE_row"+inputRowNo+" ]("+ inputReasonCode + ").xml")
def response = context.expand( '${' +name + '#Response}' )
responseFile.write(response)
OUTPUT of just clicking the PLAY button to test the groovy script.
09-01-37-475 findPersonChangeCustomerDetails - XML [request_row8 ](subsequent_given_names Invalid Format)
09-01-37-481 findPersonChangeCustomerDetails - XML [RESPONSE_row8 ](subsequent_given_names Invalid Format)
09-01-37-482 findPersonChangeCustomerDetails - XML [request_row8 ](subsequent_given_names Invalid Format)
09-01-37-488 findPersonChangeCustomerDetails - XML [RESPONSE_row8 ](subsequent_given_names Invalid Format)
note: I need the timestamp in milliseconds so i can sort the files nicely in Windows Explorer by name (otherwise there can be 2 or 3 requests sent in 1 sec which show up out of order when sorting the files)