Forum Discussion

agubba's avatar
agubba
New Contributor
7 years ago

Script assertion to assert json response

Team,

 

Step 1: I have an excel datasource with 3 columns - ID, Description and Case

Step 2: I have a rest service for which ID is a required parameter, which brings back description and case along with other parameters. A single ID can have "n" number of cases. This is a json response

Step 3: I have a data source loop, as I want to iterate this for more ID's

 

Need help in asserting the response, where the assertion should validate the combination of Description and Case together.

 

Can someone please provide the Groovy script assertion for this? I have to run this for almost 100 unique ID's

 

3 Replies

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Could you please attach the screenshot for the same? What kind of description and case you are talking about.

  • agubba's avatar
    agubba
    New Contributor

    Here is the sample json response. For a single "Id", I need to check if the response has a case and description same like as in the excel datasource. This test cases should validate whether all the rows entered in data source has a matching record in the response.

     

    Please help.

    {

        "Id": "ABC0012345",
        "Description": "Doc received",
        "System": "Manual",
        "case": "C-0601",
        "DateTime": "2017-08-31",
         "initiatedBy": "User1",
        "product": "All-MC",
        "state": "MC",
        "deliveryType": "Print",
        "docType": "Letters"
    }
    {
        "Id": "ABC0012345",
        "Description": "Doc not received",
        "System": "Manual",
        "Case": "C-0600",
        "DateTime": "2017-12-31",
         "initiatedBy": "User2",
        "product": "All-MP",
        "state": "CA",
        "deliveryType": "Fax",
        "docType": "Mails"
    }