How to do comparison of JSON response in a DevTest test script - Ensure Result Equal Assertion

book

Article ID: 141566

calendar_today

Updated On:

Products

CLOUDTEST CA Application Test CA Cloud Test Mobile MOBILECLOUD Service Virtualization

Issue/Introduction

How to  compare my JSON response to an expected model.  I am using an assertion (JSON -> "Ensure Result Equals"). 

 

 

Environment

Release : 10.5.1

Component : CA Service Virtualization

Resolution

The Ensure Result Equals assertion lets you ensure that a JSON Path result is equal to an expected value.
The following graphic shows the editor for this assertion.
 
 
On the Left Window,  you can copy any  Json text.  say for example 
In the below text: we are testing   Json data in field 2 { }  
$.transactionInteractionItemizationData[1].fields[2]
 
 
 {                 "name": "allocation",
                    "label": "Allocation",
                    "type": "TEXT",
                    "required": true,
                    "editable": true,
                    "hasMoreAllowedValues": false,
                    "uda": false
                }
 
 
 
The Xpath we provide in the JSON Xpath text box  : $.transactionInteractionItemizationData[1].fields[2]  will be verified  against the data in the Right text box.  
The right portion of the assertion editor can help you determine the values of the 
JSON Path
 and 
Expected value
 fields. First, use one of the following approaches to load the expected JSON:
  • From Content
     
    Select a file that contains the expected JSON.
  • From URL
    Enter a URL path to the expected JSON.
  • From Property
    Enter a property that defines the expected JSON. The default value is the response property for the test case.
Click on Verify Assertion.. "Run Assertion"

Attachments