Forum Discussion

venky543's avatar
venky543
New Contributor
7 years ago
Solved

Unable to transfer integer value from response to test case level property using setPropertyValue

Hi Guys,

 

I'm trying to transfer integer value from response to test case level property using setPropertyValue calling from script assertion.

 

There is a json code in the reponse with value BasePrice= 99.

 

So, i added a script assertion and wrote a script to get the value from response using JsonSlurper and stored the value into a variable = SubProducts_0_Price_11_BasePrice.

 

Now i'm trying to transfer the variable (SubProducts_0_Price_11_BasePrice) value to testCase level using below script:

 

messageExchange.modelItem.testStep.testCase.setPropertyValue("FRBasePrice",SubProducts_0_Price_11_BasePrice)

 

but i'm getting error as shown in the attached screenshot. 

 

Please help me with this.

 

ThankYou

  • Hey,

     

    Properties are saved as strings so you need to parse the value before trying to save it. Also, I would suggest to use testRunner and not messageExchange (as this is the way it is presented in the documentation and you need no imports for it). So:

     

    testRunner.testCase.setPropertyValue( "FRBasePrice", String.valueOf( SubProducts_0_Price_11_BasePrice ) )

    Let me know if it works! :smileyvery-happy:

  • Hi Lucian,

     

    Thanks a lot.

     

    Actually i'm running the script from script assertion where testRunner will not work. So, had to use messageExchange variable.

     

    it worked for me after i have mentioned "String.valueOf( SubProducts_0_Price_11_BasePrice )" in my script as below.

     

    messageExchange.modelItem.testStep.testCase.setPropertyValue( "FRBasePrice", String.valueOf( SubProducts_0_Price_11_BasePrice ) )

     

    Thank you for your help!!!

3 Replies

  • Lucian's avatar
    Lucian
    Community Hero

    Hey,

     

    Properties are saved as strings so you need to parse the value before trying to save it. Also, I would suggest to use testRunner and not messageExchange (as this is the way it is presented in the documentation and you need no imports for it). So:

     

    testRunner.testCase.setPropertyValue( "FRBasePrice", String.valueOf( SubProducts_0_Price_11_BasePrice ) )

    Let me know if it works! :smileyvery-happy:

    • venky543's avatar
      venky543
      New Contributor

      Hi Lucian,

       

      Thanks a lot.

       

      Actually i'm running the script from script assertion where testRunner will not work. So, had to use messageExchange variable.

       

      it worked for me after i have mentioned "String.valueOf( SubProducts_0_Price_11_BasePrice )" in my script as below.

       

      messageExchange.modelItem.testStep.testCase.setPropertyValue( "FRBasePrice", String.valueOf( SubProducts_0_Price_11_BasePrice ) )

       

      Thank you for your help!!!

      • Lucian's avatar
        Lucian
        Community Hero

        Aaaah I see :smileyvery-happy: Glad I could help.