Monday, January 9, 2012

soapui: logging request and response to a file

Note: this code snippet only works within a groovy script assertion for a test step. It will not work for a groovy script test step itself, because messageExchange is not available in a script test step :P


def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

def d = new Date()
newdate = d.format("yyyy-MM-dd'T'HH-mm-ss")


def myOutFile = "/home/ambar/.loadui/ambar/TrybeSoapUITest." + newdate + ".log"
def f = new File(myOutFile)

f.write("STARTING LOG...\n\n", "UTF-8")

def rawRequest = new String( messageExchange.getRawRequestData() )
f.append("\n\n\n[INFO] RAW Request Data: " + rawRequest)

/*context.currentStep.properties.each { key, value ->
  f.append("${key} : ${value.value}\n")
}*/

//f.append("\n\n\n")

//def requestHeaders = messageExchange.getRequestHeaders()
//f.append("[INFO] request headers: " + requestHeaders)

f.append("\n\n[INFO] response: " + messageExchange.getResponseContent() )
f.append("\n\n[INFO] time taken: " + messageExchange.timeTaken)

assert messageExchange.timeTaken < 10000

1 comment:

payam_prz said...

Thanks a lot!
I was looking for this for hours:
def rawRequest = new String( messageExchange.getRawRequestData() )