Trim the node value
- 4 years ago
Hi,
What you're asking for is achievable.
Firstly, how to extract the key. Below is an example groovy script to tease out that value....
def responseString = '<target_URL>: "http:/<servername>:port/k?key=abcdfee=' + '<httpmethod>GET</httpmethod>' + '<targetpayload null="true"/>' + '<isKBANeeded>true</isKBANeeded>'; def keyString = "key="; log.info(responseString); def indexOfKey = responseString.indexOf(keyString); def indexEndOfKey = responseString.indexOf("=", indexOfKey + keyString.length()); log.info("Key Start " + indexOfKey + ". Key end " + indexEndOfKey); def key = responseString.substring(indexOfKey, indexEndOfKey); log.info(key); key = key.replace(keyString, ""); log.info(key); return key;
So, after the first call that returns the 'key', create a Groovy Script step called 'GetKey' and use the above example to read the response from the first call. You will obviously have to tailor this to read from your first call.
If your second API call is in the same test, then don't bother with property transfers etc.
Simply pull in the value from the Groovy script and squirt it into the hear. Go your second API call and click on the Headers tab. Add Key ( or whatever it needs to be) and in value, you call the Groovy script...
That dollar notation is great. The above screenshot says 'call step GetKey and get the result value'. When you run your test, ReadyAPI will substiture this for the actual value.
If something isn't quite right, use the Raw tab to see the payload (with substituted variables) that ReadyAPI actually sent.
- 4 years ago
Thanks a lot !!