Ask a Question

how to transfer property from post response to a json body in post request in ready api

SOLVED
mik_fur
Occasional Contributor

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. 

 

 

Pic 1.pngPic 2.png

6 REPLIES 6
richie
Community Hero

Hi @mik_fur,

When you say youve tried a couple of ways, what ways have you tried? You have several options to do a property transfer.

If you can supply request1's response along with request2's json (data doesnt matter, json structure does matter), we should be able to sort an answer out for you.

If you supply the testcase names as well as your test step names that can only help

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
mik_fur
Occasional Contributor

Approaches Tried

I tried the following:

  • created a property at the testsuite level to call in the test step
  • created Property Transfer step (tried diff syntax for property expansion)
  • created Properties step

 

 

1st Request – create_authCode

Header

  • Client
  • Customer_facing_tool
  • Interation_ID

 

Body

{

  "emailAddress" : "xxx.xxx@xxx.com"

}

 

 

1st Response – create_authCode

{

   "authCode" : "911284"

}

 

 

2nd Request – validate_authCode

Header

  • Client
  • Customer_facing_tool
  • Interation_ID

 

Body

{

  "authCode" : "${#create_authcode#authCode}",

  "emailAddress" : "xxx.xxx@xxx.com"

}

 

nmrao
Champion Level 3

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.


Regards,
Rao.
richie
Community Hero

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

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
mik_fur
Occasional Contributor

Thanks Riche.  I will keep in mind the camel naming convention

mik_fur
Occasional Contributor

Thanks Rao

cancel
Showing results for 
Search instead for 
Did you mean: