Forum Discussion
SmartBear_Suppo
Alumni
17 years agoHi Arun and Lens,
The code snippet from Lens is pretty much spot on with a slight change that new operator in Groovy (just like in Java and many other object oriented languages) should be lower case. Apart from that, I would also suggest using lowercase first letters in variables as well as other Sun's Java naming conventions since they have been widely accepted. In additional, using them will spare you from being identified as Visual Basic programmer.
In this case, File variable could be confused with class with the same name and capitalization.
I would propose an improvement to solution Lens which logs response into a file with a generated filename that includes time stamp (so that all responses can be sorted chronologically). Creating a se
Here's the snippet of a utility method logResponseToFile(testStepName) with my humble corrections:
Have in mind that using pro version of soapUI you can put the corresponding Groovy script into $SOAPUI_HOME/bin/scripts and have this neat functionality available in any soapUI project. In that case the only line in your Groovy script is this:
If the supplied test case in not found, an error will be reported without disrupting soapUI tests being run.
Future pro versions of soapUI will contain improved version of this Groovy script.
Cheers!
/Nenad Nikolic a.k.a. Shonzilla
The code snippet from Lens is pretty much spot on with a slight change that new operator in Groovy (just like in Java and many other object oriented languages) should be lower case. Apart from that, I would also suggest using lowercase first letters in variables as well as other Sun's Java naming conventions since they have been widely accepted. In additional, using them will spare you from being identified as Visual Basic programmer.
In this case, File variable could be confused with class with the same name and capitalization.I would propose an improvement to solution Lens which logs response into a file with a generated filename that includes time stamp (so that all responses can be sorted chronologically). Creating a se
Here's the snippet of a utility method logResponseToFile(testStepName) with my humble corrections:
def getResponseFilename(name) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('yyyyMMdd-kkmmss')
shortDate = dateFormat.format(date)
respFilename = shortDate + "-" + name + "-response.xml" // implicitely returned
}
def saveResponseAsFile(testStepName) {
def file = new PrintWriter (getResponseFilename(testStepName))
if (log.isInfoEnabled())
log.info("Opening response file: " + respFilename)
def response = testRunner.testCase.testSteps[testStepName].testRequest.response.contentAsString
file.println(response)
file.flush()
file.close()
if (log.isInfoEnabled())
log.info("Saved response in file: " + respFilename)
}
logResponseToFile("My test step name")
Have in mind that using pro version of soapUI you can put the corresponding Groovy script into $SOAPUI_HOME/bin/scripts and have this neat functionality available in any soapUI project. In that case the only line in your Groovy script is this:
soapui.utils.LogUtils.logResponseToFile("My test step name", testRunner, log)
If the supplied test case in not found, an error will be reported without disrupting soapUI tests being run.
Future pro versions of soapUI will contain improved version of this Groovy script.
Cheers!
/Nenad Nikolic a.k.a. Shonzilla