Forum Discussion

agubba's avatar
agubba
New Contributor
7 years ago

How to write results back to Data source using Groovy

Hello,

 

I am testing a REST API and the response is retrieved in Json. I am using an excel data source with multiple rows of test data in it. Is there a way to write back results of a groovy script step to the same excel data source in a new column against each row of test data?

 

If Yes, kindly provide the steps to do the same.

 

Thanks,

Abhishek

4 Replies

  • PM's avatar
    PM
    Contributor

    even i hv the same query 1 was able to get the data by adding the data source as excel but hot to update Excel with the output of the response . 

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Hey, Did you mean this?

     

    def response = context.expand(${Request#Response})

     

    testRunner.testCase.testSteps["DataSource"].setPropertyValue("Response", response)

    • PM's avatar
      PM
      Contributor

      Yaaa ! but was thinking if it can b done w/o groovy ....like we add data source as excel in Test for data driven approach so we can get the response update in the same Excel . 

      • avidCoder's avatar
        avidCoder
        Super Contributor

        Then, manually you need to create Properties test step and then inside Request test step you need to parameterize the things wit the value. Like this :-

         

        {

         "id": "234"

         "name": "Donny"  (Parameterize the value of "name". Right click and Get Data from properties and set it here..)

        }

         

        New Request looks like this:-

         

        {

         "id": "234"

         "name": "${Properties#name}"

        }

         

        And inside Properties test step click on + sign and add Property Key as "name" and Value as "Donny"

         

        Hope it will help you out.