how to transfer property from post response to a json body in post request in ready api
I have a Rest Service which has Post methods. I have 2 testcases in a test suite. From the first testcase, I need to get a property from the JSON response and pass it to the 2nd testcase into the JSON body of the request. I have tried a couple of different ways to set this up but have been unsuccessful.
- Thumb rule is to have each and every test independent.
In this particular case, you could generate the auth code as part of setup script instead of separate test case, then extract the value and save it testsuite level, AUTHO_CODE and use ${#TestSuite#AUTH_CODE} in your tests whereever it is needed. Hi,
Rao's advice is correct - it's always better to keep your tests independent - however I'll let you deal with that - I just wanted to highlight you were actually almost there with your setup and a couple of points that might help you going forward.
Using camel case to name your items is dodgy cos its so easy to forget. I have a rule (Which I always forget) but I tend to try and only use upper camel case or not at all - just so I don't make a silly mistake. you haven't made a mistake here - but I'm just highlighting your 1st request (create_authcode) doesn't use camel case at all, your 2nd request uses lower camel case (validate_authCode)
There are 2 concepts that aren't immediately obvious when doing property transfers - using Scope to in your transfers and using specific object names in your property transfer - if you use 'scope' - you are essentially selecting a 'level' within yoru project hierarchy - so Project, TestSuite, TestCase, TestStep - so you're selecting a level - NOT specifying a specific testsuite, testcase, or teststep
Scope prop transfer syntax = ${#ScopeLevel#PropertyName}
Specific item prop transfer syntax = ${TestStepName#PropertyName}
So - you tried specifing "${#create_authcode#authCode}" in the body of the 2nd POST and this didnt work because:
You first test step is entitled 'create_authcode'
The attribute in the first response you are transferring is entitled 'authCode'
So you needed to have the prop transfer configured as "${create_authcode#authCode}"
I appreciate Rao's advice is better in regards to efficiency/maintainability and all that stuff - so you should really think about doing that instead - but I just wanted to highlight why your attempt didnt work so you'll know in future for any other property transfers
nice one
rich