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!!!