Service Virtualization

 View Only
Expand all | Collapse all

I am trying to assert expected values in an excel against the actual values contained inside a json response in our project. We use array type to access the elements inside a json response. Trying to assert excel against json, so far unsuccessful.

  • 1.  I am trying to assert expected values in an excel against the actual values contained inside a json response in our project. We use array type to access the elements inside a json response. Trying to assert excel against json, so far unsuccessful.

    Posted Oct 09, 2017 05:41 AM

    #monikamehta4453146

    For Example, a part of the json response looks like this:

     

    {
    "Incentives": [
    {
    "given": true,
    "Type": "Universe/CUSTOMER/CUSTOMER",
    "Incentive_Request_desc": "REQUEST_MSISDN_BLOCK"
    },
    {
    "given": true,
    "Type": "Universe/CUSTOMER/CUSTOMER",
    "Incentive_Request_Desc": "CHANGE_RATE_PLAN"
    },

     

    Suppose I have an excel with the following values

     

    Eligible         Type                                                      Dec

    true         Universe/CUSTOMER/CUSTOMER         CHANGE_RATE_PLAN

     

    I am trying to take each of these three values and individually assert them against their corresponding type in json response i.e. Eligible column value will be asserted against "given" field value in json response.

     

     

    ***************** UPDATE ************************

    #monikamehta4453146

     

    I am using the assertion "Ensure result contains" and validating excel columns against json response populated into parameters. This works.

     

    When I use scripted assertion using ".contains" or ".equals", I am getting the following error 

     

    "
    } execution error so we assume false: javax.script.ScriptException: bsh.EvalError: Sourced file: inline evaluation of: ``// This script should return a boolean result // indicating the assertion is t . . . '' : Typed variable declaration : Class or variable not found: splitJsonOutput.length : at Line: 17 : in file: inline evaluation of: ``// This script should return a boolean result // indicating the assertion is t . . . '' : splitJsonOutput .length
    in inline evaluation of: ``// This script should return a boolean result // indicating the assertion is t . . . '' at line number 17"

     

    The script does return a boolean true if "if condition" is met, else returns false on the contrary.

     

    Please advise.



  • 2.  Re: I am trying to assert expected values in an excel against the actual values contained inside a json response in our project. We use array type to access the elements inside a json response. Trying to assert excel against json, so far unsuccessful.
    Best Answer

    Broadcom Employee
    Posted Oct 16, 2017 10:06 AM

    Monika,  are you using the Json assertion: Ensure Result contains  or Ensure Result equals? 

     

    I created a Json  Xpath filter for example - {{mytype}} =    $.Incentives[1].Type    and this gave me a value:  Universe/CUSTOMER/CUSTOMER

     

    Then asserted on this  filter.    Let me know if that works for you..

     

    if not,  please open a ticket with  CA Support.  



  • 3.  Re: I am trying to assert expected values in an excel against the actual values contained inside a json response in our project. We use array type to access the elements inside a json response. Trying to assert excel against json, so far unsuccessful.

    Broadcom Employee
    Posted Oct 16, 2017 10:22 AM

    If you want to loop through the JSON array and compara a value from your Excel. Set i=0 in the test first and change  the JSON Path filter $.Incentives[1].Type==>$.Incentives[i].Type. This will give you the first value of "Type" and you can compare it with value from your Excel using assertion. If the assertion results false then you can increment "i" and get the next value from JSON array and compare.



  • 4.  Re: I am trying to assert expected values in an excel against the actual values contained inside a json response in our project. We use array type to access the elements inside a json response. Trying to assert excel against json, so far unsuccessful.

    Posted Oct 19, 2017 12:08 AM

    Can you share your script/code? It's complaining about line 17 so that's a good starting point to debug. It's also a good idea to print debug output to ensure the logic in your script is correct.