Forum Discussion

divyap24's avatar
divyap24
New Member
7 years ago

How to take a value from the request & save as a global property when the response is positive

How to take a value from the request & save as a global property when the response is positive.

 

The value which is passed in a SOAP request & when it's corresponding response is positive, I need to save the request's particular parameter value in the Global property.

 

Suggest me the ways to do it

1 Reply

  • 1-Run your rest step once with positive data

    2-Add a groovy script in your test case .

    3-Right click and select Get Data.

    3-Go to your rest case and select the test step

    4- Add harResponse .

    5- In harResponse, there will be #status# which return a code . It returns 2 different code,one for positive & one for negative (please check once with your data) 

    6-Select #status# from harResponse . (This will give you idea whether your test step is passed or failed )

     

    Example

    def  harResponse = context.expand( '${#[TestSuite#TestCase#RestStep]#HarResponse#$[\'headers\'][0][\'value\']}' )

     

    let suppose expected #status#="HTTP/1.1 201"

     

    Solution_1

     

    After that use this code

     

    if(harResponse_StatusCode.equals(harResponse))

    {

        //get your data from rest step in the same way as above mention(this time select response in place of harResponse)

     

       Example

       def getResponseInfo = context.expand( '${#[TestSuite#TestCase#RestStep]#Response#$[\'responseInfo\']}' )

     

       def globalProperties=com.eviware.soapui.SoapUI.globalProperties

       globalProperties.setPropertyValue("SetGlobalpropertyName", "$getResponseInfo")

    }

     

     

    Solution_2

     

    try{

           

            //get your data from rest step in the same way as above mention(this time select response in place of harResponse)

     

            Example

            def getResponseInfo = context.expand( '${#[TestSuite#TestCase#RestStep]#Response#$[\'responseInfo\']}' )

             

             def globalProperties=com.eviware.soapui.SoapUI.globalProperties

             globalProperties.setPropertyValue("SetGlobalpropertyName", "$getResponseInfo")

      

          }

    catch(Exception)

    {

       log.error " rest step is failed "

    }

     

    Hope this will help you,let me know if you face any problem.