Through a groovy teststep in soapUI i want all request and response files to be stored in a local directory with system date.
The groovy teststep in soapUI:
There are several ways of doing this. One would be creating a Groovy test step with the following script:
def myOutFile = "C:/Temp/MyOutDir/response.xml"
def response = context.expand( '${MyTestRequest#Response}' )
def f = new File(myOutFile)
f.write(response, "UTF-8")
Try to use SoapUI
's tools to select the value of whatever you want.
Right click on the groovy
editing area, choose Get Data
--> your test suite --> your test case --> your test step --> response
. This will get you the entire response. You can also dive deeper into the response
with this method.
Check out the answer by McDonald. Best way to save and shoot request.
http://www.loadui.org/forum/viewtopic.php?f=5&t=16354#p38935
There is a shorter syntax. Logic is similar what @robert Shared
def response=context.expand('${TestRequest#RawRequest}')
new File("c:/testpath/input.xml").write(response)
if you want to reduce it to just one line
new File("c:/testpath/input.xml").write(context.expand('${TestRequest#RawRequest}')
You can replace RawRequest with whatever you want to save
Request or Response
RawRequest is used when you want data replacing the variables used in request
More useful if we should save an error in Response:
import com.eviware.soapui.support.XmlHolder
import java.text.MessageFormat
import org.apache.commons.lang.ObjectUtils
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def retrieve = groovyUtils.getXmlHolder("MyTestRequest#Response" )
if (!ObjectUtils.equals(retrieve.getNodeValue("//*:xpath"), "string")){
def currentTime = System.currentTimeMillis()
def fullFilePath = context.expand('${projectDir}') + File.separator + "Fail-"+currentTime+".xml"
def reportFile = new File(fullFilePath)
if (!reportFile.exists())
{
reportFile.createNewFile()
reportFile.append((Object)retrieve.getPrettyXml(), 'UTF-8')
}
}