Forum Discussion

maxrussell's avatar
maxrussell
Contributor
4 years ago
Solved

Reading excel column into property, parsing REST response for property member

In a test case, I have a data source step. It reads a column range into a property. When I run the step, the data log shows each row from the desired column range.   I have a REST request after da...
  • PrathapR's avatar
    PrathapR
    4 years ago

    Got it now,

     

    Test Step Structure:

    Please keep your test steps structure like below.

     

     

     

     

     

     

     

     

     

    and when you select "data source loop" select options like below,

     

     

     

     

     

     

     

     

     

     

     

     

     

    and please keep below code in groovy script step (Data validation in above image)

    Code:

    //import library to parse JSON
    import groovy.json.JsonSlurper

    //get the JSON response from the test step that makes the call to some test step to get a JSON response
    def response = testRunner.testCase.getTestStepByName("GetEmployees").getPropertyValue("Response")

    def responseJSON = new JsonSlurper().parseText(response)

    //verify the slurper isn't empty
    assert!(responseJSON.isEmpty())

    def attrName = context.expand( '${DataSource#attribute_name}' )

    assert(responseJSON.toString().contains(attrName)): "attrName $attrName doesn't exists in response"

     

    Note: if your response have multiple arrays, and objects. and the assertion attribute coming in particular array/object please navigate to that and do assertion so it will reduce time complexity.

    Ex: assert(responseJSON[i].employees[j].accounts.toString().contains(attrName)): "attrName $attrName doesn't exists in response"