Forum Discussion

cata12's avatar
cata12
Contributor
7 years ago

Selecting a specific item from a JSON Node value

Hi all,

 

I insert a new record using ReadyAPI 2.1.0 and get the request response in a JSON Node like the one posted below:

 

JSON Node: resultPayload

 

Value:

{
"x.metadata":"http://test:111/$metadata#Cars/@Element","CarId":2,"New":false,"CarId":102,"CarName":"New Car 2017-12-14T12:10:00 719","Weight":"1200

kg","CarNumber":25,"SupplierId":1,"CarPrice":"10.0000","UnitsInStock":13,"UnitsOnOrder":70
}

 

How can transfer the "CarName" value only ("CarName":"New Car 2017-12-14T12:10:00 719") in another request or how can I validate that in the next request (which gets all the car names) the CarName posted above is present ?

 

The available assertions only let me select the entire JSON Node and having the CarName as a property doesn't really help because each time the request is sent a new car name is generated.

 

I've also tried something like this to validate that my car name is displayed after I insert it:

GET: http://endpoint/Cars/${#TestCase#CarName} 

GET: http://endpoint/Cars/?CarName=${#TestCase#CarName}

 

but these requests return then entire list of cars

 

Also is it possible to use Property Transfer for that car name only ?

 

Thanks

  • I solved this by creating a script which generates an unique CarName in a property (which is then used in the request I posted above) then used JSONPath Match Assertion to check if the CarName generated by the script == CarName from the next request's response

  • I solved this by creating a script which generates an unique CarName in a property (which is then used in the request I posted above) then used JSONPath Match Assertion to check if the CarName generated by the script == CarName from the next request's response