Forum Discussion

alfonsolft's avatar
alfonsolft
Occasional Contributor
7 years ago
Solved

Re: Property Transfer Test Step adding extra bracket in the value

Hi,

I have the same problema that Nhan.  I have the following response JSON´s service

{
   "data":    {
      "idSesion": 7,
      "seed": "EFER642XVE5PF2OE"
   },
   "idAplicacion": 1,
   "idOperacion": 1,
   "idProducto": 176,
   "statusMensaje": 1,
   "statusOperacion": 1
}

I want to use the next  value seed in the next  JSON´s service. Im trying use Property Transfer, but  I can´t do it . Could you help me?

 

 

  • Add the JSON path expression $.data.seed under the source Login Request 1 then you should see the transferred value.

  • nmrao's avatar
    nmrao
    7 years ago
    alfonsolft, it was mentioned in the earlier reply

    ie., use ${#TestCase#SEED} in other steps.
  • nmrao's avatar
    nmrao
    7 years ago
    As you can see the error message:
    It is line 1, column1

    where the script is even not started. May be so copy paste or special invisible characters? not sure.
  • PaulMS's avatar
    PaulMS
    7 years ago

    Hi

    The script assertion would need to be added to the first request. If added to the second request the response will be different and the script would fail.

    The result of the property transfer step is the same anyway so you can choose whichever method is easier.

9 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    alfonsolft,

     

    Not really familiar with JSONPath.

     

    You can use Script Assertion for the REST Request step and remove Property Transfer test step and use below code for Script Assertion:

     

     

    assert context.response, 'Response is null or empty'
    
    def json = new groovy.json.JsonSlurper().parseText(context.response)
    assert json.data.seed, 'Seed value in the response is empty or null'
    
    //Store seed value in test case level custom property
    
    context.testCase.setPropertyValue('SEED', json.data.seed)

    In the following steps, wherever SEED value is needed use ${#TestCase#SEED}

    • alfonsolft's avatar
      alfonsolft
      Occasional Contributor

      Thanks Nmrao ,

       

      This is first time that I´m going to use a  "Script Assertion".  How  Can I use the SEED from the response JSON´s service in the followings request?.

       

      Annex the json service screen

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        alfonsolft, it was mentioned in the earlier reply

        ie., use ${#TestCase#SEED} in other steps.
  • PaulMS's avatar
    PaulMS
    Super Contributor

    Add the JSON path expression $.data.seed under the source Login Request 1 then you should see the transferred value.