Forum Discussion

Makhlo's avatar
Makhlo
Occasional Contributor
15 years ago

Groovy teststep: Stores request/respons files in local drive

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:

def name = context.expand( '${Input#TG}' )
def locatie = context.expand( '${#TestCase#locatie}' )

def createFolder(locatie) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('ddMMyyyy')
shortDate = dateFormat.format(date)
outputFolder = locatie+shortDate
createFolder = new File(outputFolder)
createFolder.mkdir()
}

def getResponseFilename(shortDate,name) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('ddMMyyyy HH:mm:ss')
shortDate = dateFormat.format(date)
respFilename = shortDate+"_"+name+"_response.xml"
}

def getRequestFilename(shortDate,name) {
date = new Date()
dateFormat = new java.text.SimpleDateFormat('ddMMyyyy HH:mm:ss')
shortDate = dateFormat.format(date)
reqFilename = shortDate+"_"+ name+"_request.xml"
}

def file = new PrintWriter (createFolder(locatie)+getResponseFilename(shortDate,name))
def response = testRunner.testCase.testSteps["CheckAdres"].testRequest.response.contentAsString
file.println(response)
file.flush()
file.close()

def file2 = new PrintWriter (createFolder(locatie)+getRequestFilename(shortDate,name))
def request = context.expand('${CheckAdres#Request}')
file2.println(request)
file2.flush()
file2.close()


I get the following error:

groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.plus() is applicable for argument types: (java.lang.String) values: [14062011 14:28:45_happyFlow_response.xml] Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object), split(groovy.lang.Closure), wait(), any(), dump()

Can someone please tell me how to solve this error ?

1 Reply

  • Finan's avatar
    Finan
    Frequent Contributor
    You could start with a different date format, since ":" is not accepted in a filename, try:
    shortDate = new Date().format("ddMMyyyy HHmmss").toString();


    The error occurs because of your line:
    def file = new PrintWriter (createFolder(locatie)+getResponseFilename(shortDate,name))


    If I run the following line against your script, it returns a boolean, hence the boolean.plus.
    log.info createFolder(locatie)


    The script seems to run if I add the following line at the end of createFolder(locatie):
    return outputFolder