Ask a Question

Dynamic Assertion : Resolving Property in Assertion for JSON Path

Sriraj
Contributor

Dynamic Assertion : Resolving Property in Assertion for JSON Path

Hi , 

 

I have a JSON path evaluation in one of the assertions where the path is created dynamically based on a value from the response field , Example below .

 

[?(@.Some_Id_c=='${#EmployeeId}')].Order_Status_Id__c

 

The above path has been configured in the JSON path expression match Assertion where the expected value at the node is = Received.

 

The value for the property EmployeeId is captured in one of the steps before running the above assertion .

 

 

What i see that when the assertion is resolved , the value for Employee ID is not considered and thus the assertion fails.

 

 

Can someone help me with this ? 

5 REPLIES 5
nmrao
Community Hero

May be if you can show the json and what do you need to assert, that would be helpful.


Regards,
Rao.

@nmrao thanks for the note. 

 

Consider the JSON snippet Below.

 

"Name": "ABC",
"Item_Id": "<EmployeeId>",
"Status_Id": "Received",
"Points": 5,

An assertion with the below path will yield value as "Received"

 

[?(@.Item_Id=='${#prop_EmployeeId}')].Status_Id.

 

 

However in my case the value which goes in the property <prop_EmployeeId> is captured from a response and this is got at run time .

 

 

I want to use this property prop_EmployeeId which is filled at run time and place it in the JSON path in the assertion so that i can validate the value "Received".

 

Please let me now if you need more information

HKosova
SmartBear Alumni (Retired)

You need to prefix the property name with the corresponding scope, such as ${#Project#EmployeeId} if it's a project property  or ${#TestCase#EmployeeId} if it's a test case property.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

@HKosova Right. i was concentrating on the problem statement thus did not add the testcase name etc..

HKosova
SmartBear Alumni (Retired)

Given the exact JSON

{
  "Name": "ABC",
  "Item_Id": "<EmployeeId>",
  "Status_Id": "Received",
  "Points": 5
}

your JSONPath should work fine, provided that the property name, scope and value are correct:

[?(@.Item_Id=='${#TestCase#EmployeeId}')].Status_Id

 

If the object you are testing is nested inside another object, such as:

{
  "something":
  {
    "Name": "ABC",
    "Item_Id": "<EmployeeId>",
    "Status_Id": "Received",
    "Points": 5
  }
}

you need to specify the path from the root object, e.g.:

$..[?(@.Item_Id=='${#TestCase#EmployeeId}')].Status_Id

 

If you post the exact JSON, we could give a more precise answer.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: