Ask a Question

How pull property value to the next json body request using proprty transfer?

Titanium22
Occasional Contributor

How pull property value to the next json body request using proprty transfer?

Hey hey, lovely community! I need your lovely little support 😄

 

I am testing API on one project. So, and faced with a question:

How pull property value which was taken in response to the next property in JSON body request using proprty transfer?

 

What I have

1. I have a request to a server from where I get a property in JSON body response which I want to move as value to the next 

body request. Here is screenshot: http://joxi.ru/KAgGBgeH4Ebx7A

 

And

Question number 2 is how to take this value http://joxi.ru/D2PQdzJHpqzoeA from a header and pull into the header parameter "cookie" in next request?

 

Please, need your little support, ladies and gents!

7 REPLIES 7
PaulMS
Super Contributor

Re: How pull property value to the next json body request using proprty transfer?

1. Add a property transfer test step then select the required source test step, source property = Response, source language = JSONPath, and selection from source property = $.sms_code.  You can then use the target property in the next request with Property Expansion

 

2. Try a Groovy script to Pass cookie value to another request

nmrao
Community Hero

Re: How pull property value to the next json body request using proprty transfer?

Not much familiar with Json Path along with Property Transfer. I would prefer to do it using Script Assertion for the first request test step.

 

The following Script Assertion would fetch the required value and set the value test case level custom property and access the value using property expansion in the following test steps.

 

assert context.response, "Response is empty of null"
def parsedJson = new groovy.json.JsonSlurper().parseText(context.response)
log.info "Retrieved sms code : ${parsedJson.sms_code}"

assert parsedJson.sms_code, "sms code is null or empty in the response"

context.testCase.setPropertyValue('SMS_CODE', parsedJson.sms_code.toString())

In the following request, use ${#TestCase#SMS_CODE} where you needed that value.

 

And regarding your 2nd question, please refer the below script which is done some time for similar requirement.

 

https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/AddCookiesToNextRequest.groovy



Regards,
Rao.
Titanium22
Occasional Contributor

Re: How pull property value to the next json body request using proprty transfer?

I've tried your way and it doesn't work. I think that I specified it in an incorrect place.

http://joxi.ru/l2Z6x4buwzqNp2

 

Could you please clarify this moment?

Titanium22
Occasional Contributor

Re: How pull property value to the next json body request using proprty transfer?

Can we have a fast skype call?:) Because it doesn't work for me still doesn't work. http://joxi.ru/823pvd6fJ91M3A - is it correct?

nmrao
Community Hero

Re: How pull property value to the next json body request using proprty transfer?

It was clearly mentioned that you need to use the provided script as "Script Assertion" for the request step where you get the response, no additional "groovy script" test step is needed.


Regards,
Rao.
Titanium22
Occasional Contributor

Re: How pull property value to the next json body request using proprty transfer?

I've got the problem. Thanks. Now it works.

And what can be the reason of this behavior? Why "phone" property is not moved to request?  - http://joxi.ru/VrwlzEXuO7NZLm

PaulMS
Super Contributor

Re: How pull property value to the next json body request using proprty transfer?

Titanium22

 

At first glance, you need to specify the JSONpath expression to use the phone data from a previous request message

 

${Teacher_Create#Request#$.phone}

or

${Teacher_Create#Request#$['phone']}

 

Point and Click Testing

cancel
Showing results for 
Search instead for 
Did you mean: