Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

how to assert json response based on test case in excel spreadsheet.

Options
rickstag
rickstag Posts: 16

How can I do the following. This is pseudo code.

If test case from excel spreadsheet = 'test_1' then
validate element_1 in json return value is equal to "true"

I tried to use a json assertor that does reference (lists) my excel dataset but there is no way to reference a column from that dataset. I can only reference elements in the json response.

I am familiar with the assertions types in the JSON Assertor but cannot find anyting that lets me reference my input dataset.

I did read
https://forums.parasoft.com/discussion/2766/json-rest-api-validate-multiple-responses-against-a-datasource

but I have to feel there is an easier way.

Can someone write the simple steps to accomplish this basic idea or let me know that the only way to do this is to write data from my input file and data from my response to an output file then read the output file in and compare the results. If it is the latter can you write the simple steps to do this. Like.
How to write a row from my input data set to a writeable file then how to append to that writeable file from my json response.
Or
can I access the excel spreadsheet row and the json response from a groovy script and do the work there.

Thanks,!!

Comments

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭
    Options

    Create a test suite level variable and get that control parameter in an variable

    Then Goto TestSuite --> Execution Options --> Test Flow logic --> Select Your Assertion --> Use the created variable to control it.

  • rickstag
    rickstag Posts: 16
    Options

    Thanks for the information. I would have to add a lot of variables which would be no different then having many separate tests. I was also unclear what the two options on the do statement meant on the Test Flow Logic. I will read up on them.

    At this point I am going to try one of two things. This technique
    https://forums.parasoft.com/discussion/2984/how-to-assert-service-response-values-against-a-database

    Or try and find out how to access a variable that I put in a properties file in a groovy script like

    context.put("testName",value);
    String testName = context.get("testName");
    Application.showMessage("testName is " + testName)

    Thanks for taking the time to respond.

  • rickstag
    rickstag Posts: 16
    Options

    I have solved the problem by using a custom assertion and using groovy. Here is a snippet.
    import com.parasoft.api.*;

    boolean customAssertion(Object input, ScriptingContext context) {
    String testName = context.getValue("header tests", "test_name")
    String expectedMessage = context.getValue("header tests", "expected_message")
    String statusCode = context.getValue("header tests", "status_code")
    Application.showMessage("test_name from data source is :" + testName)
    Application.showMessage("expected_message from data source is :" + expectedMessage)
    Application.showMessage("status_code from data source is :" + statusCode)
    Application.showMessage("Object input is :" + input.toString())
    if (statusCode.equals("400")){
    switch (testName) {
    case "FID-LOG-TRACKING-ID_NEG_1":
    rval = expectedMessage
    default:
    rval = "failed test 1"
    }
    } else {
    rval = "failed test 2"
    }

    Application.showMessage("Returning value is :" + rval)
    return input.toString().equals(rval);
    

    }