richie
7 years agoCommunity Hero
Capture Header Value For Property Transfer
Hi,
I need to transfer the value of a custom header from a response to pass onto a subsequent GET request.
I found the following (which is very helpful) but I'm a little stuck
My test hierarchy is as follows:
POST (payload embedded on request) GroovyScript (to grab the 'originalFilename' header from POST response) Properties (to hold the 'originalFilename' property value) GET (to retrieve a record based on the 'originalFilename' property value)
the other page indicates the following groovy can be used to extract a header value:
//Takes one of the elements of the response Header def value = testRunner.testCase.testSteps["POST"].testRequest.response.responseHeaders["originalFilename"] //Read this value into a parameter def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) groovyUtils.setPropertyValue("Properties", "originalFilename", value.toString())
HOWEVER - the property value is returned within square brackets [] which the other page indicates is cos its an 'array to string'.
It suggests altering the
groovyUtils.setPropertyValue("Properties", "originalFilename", value.toString()) to groovyUtils.setPropertyValue("Properties", "originalFilename", cookie_vals.[0])
HOWEVER - the above doesn't work.
Does anyone know how I can alter the groovy slightly so the value is not returned within square brackets?
thanks to all!
richie
Remove the dot before [0] and toString() is probably not necessary as the property value will always be set as string.
groovyUtils.setPropertyValue("Properties", "originalFilename", value[0])