cancel
Showing results for 
Search instead for 
Did you mean: 

Tranfert part of a header response as a property

SOLVED
Highlighted
New Contributor

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/0000000004
Date: Wed, 14 Sep 2016 15:05:00 GMT
Connection: close

 

What I want to do is to take the identifier, here "0000000004", after "identifiers/" of the header "Location" and transfer it to another test case further.

 

How can I do that ?

Thank you very much,
Julian

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Tranfert part of a header response as a property

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+\//,'') log.info "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}')


Regards,
Rao.

View solution in original post

4 REPLIES 4
Highlighted
Community Manager

Re: Tranfert part of a header response as a property

Hi Julian,

 

 

It sounds like the Property Transfer TestStep is what you need. Take a look at this article:

http://readyapi.smartbear.com/structure/steps/property/transfer/intro/start

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
New Contributor

Re: Tranfert part of a header response as a property

Hi Tanya,

 

I'm trying to use the Property Transfer TestStep but I don't see any solution to catch a part of the header response in the tutorial.

 

Thank you.

Julian

Highlighted
Community Hero

Re: Tranfert part of a header response as a property

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+\//,'') log.info "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}')


Regards,
Rao.

View solution in original post

Highlighted
New Contributor

Re: Tranfert part of a header response as a property

Thank you very much, that's what I needed.

 

Julian

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors