Forum Discussion

JulianTest's avatar
New Contributor
8 years ago

Tranfert part of a header response as a property

Hello, I'm in front of something new and I don't know how to solve it. I have a step case where I get this raw response : HTTP/1.1 204 No Content Server: Apache-Coyote/1.1 Location: identifiers...
  • nmrao's avatar
    8 years ago

    I would suggest to use Script Assertion over Property Transfer test step. i.e., Add the script assertion to the request step and remove property transfer step altogether.


    The below script would read the given header, trims the required value and set that value at test suite level, so that all the remaining test cases can use that location value.


    //If you need it for another header, please change the value of key below
    def key = 'Location' if (messageExchange.responseHeaders.containsKey(key)) { def result = messageExchange.responseHeaders[key] def locationValue = result[0].replaceFirst(~/\w+\//,'') "Setting the location value ${locationValue} at suite level" context.testCase.testSuite.setPropertyValue('LOCATION_VALUE', locationValue) } else { log.error "Response does not contain header : ${key}" }

    In the following test cases use location as given below:


    • If the step is request step (soap / rest etc.,), use ${#TestSuite#LOCATION_VALUE}
    • If the step is of groovy script step, use  context.expand('${#TestSuite#LOCATION_VALUE}')