Contributions
Re: Groovy script - Sum two values of REST response and pass the sum on to the next request
HiChrisAdams Thanks for the tip! I was not aware that I could use the Get Data - dialog also in this window which makes it totally easier. Just one minor correction to your sample: The apostrophe has to be escaped using \ Like that: def value = context.expand('${CheckContingentStartTimes#Response#$[\'ContingentStartTimes\'][\'ContingentStartTime\'][0][\'Price\'][\'value\']}}'); But anyways, that helped! Thank you a lot! Best regards, Markus3 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.7KViews0likes1CommentRe: Groovy script - Sum two values of REST response and pass the sum on to the next request
HiChrisAdams Thank you very much for your help. Unfortunately when trying to run the script as a test step, I am receiving the following error: Here's the minimalistic script I configured: def value = ${CheckContingentStartTimes#Response#$['ContingentStartTimes']['ContingentStartTime'][0]['Price']['value']}; log.info("${value}"); It seems to have an issue with how I adressed the field? Though this notation is working when using it as a field in the request using the Get Data - dialog. Thanks in advance for your assitance. Best regards, Markus3 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.7KViews0likes5CommentsGroovy script - Sum two values of REST response and pass the sum on to the next request
Hi! I'm currently utilizing ReadyAPI for functional tests of our API. I am already using "simple" property transfer / Get Data to pass on a value from one test step REST response to the next REST request like: ${TestStep1#Response#$['ABC']['Array'][0]['Price']['value']} Now what I want to achieve is passing on the sum of two values of a response to the next request. E.g. let's say Test Step 1 Response gives me the following data: Now I want to pass on the sum of the prices (1.4 + 2 = 3.4) to a field of the next request. I was told by Smartbear Support that this can be achieved using Groovy scripts but they do not offer customer support for scripts and I was referred to this Community form. As I am totally new to Groovy Script and not sure about how to use it for my goal which isn't complex at all but again, I have never used Groovy Script before, I am asking if someone could help of an example of how this would look like? Maybe also with an example if the values were returned in string format and I would need to parse them to Double first? Thank you!Solved3 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.9KViews0likes7Comments