Forum Discussion

Titanium22's avatar
Titanium22
Occasional Contributor
8 years ago

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

Hey hey, lovely community! I need your lovely little support :D

 

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!

  • nmrao's avatar
    nmrao
    Champion Level 3

    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

      • nmrao's avatar
        nmrao
        Champion Level 3
        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.