Forum Discussion

anallagundla's avatar
anallagundla
Contributor
14 years ago

How to read data source values to list using groovy script?

Hi /Ole

I have a datasource, which has one column with 10 values. I want to be able to read them through another groovy script, How do i do that?

Datasource

Id
1
2
3
4
5

When I use below code, I only get last id, in this case "5"

def ds = testRunner.testCase.testSteps['DataSource']
rowAdd = ds.getPropertyValue("Id")
listId.add(rowAdd)

How do i get all the values from data source to list?

Abhinav

8 Replies

  • Hello,

    Can you please provide more context around what you are doing, this should be possible without scripting in SoapUI Pro.

    Regards,
    Temil
  • Hi,

    you have to manually move the datasource to the next row - try the following:

    def ds = testRunner.testCase.testSteps['DataSource']
    rowAdd = ds.getPropertyValue("Id")
    listId.add(rowAdd)

    while( ds.next( testRunner, context ))
    list.add( ds.getPropertyValue("Id") )
    ...

    Hope this helps!

    /Ole
    SmartBear Software
  • Hi,
    I use below code to read values from Data Source through groovy script, but only get last value. What is wrong?

    def listClicks = []
    def ds = testRunner.testCase.testSteps['DataSource']

    rowAdd = ds.getPropertyValue("agname")
    log.info(rowAdd)

    listClicks.add(rowAdd)
    while(ds.next( testRunner, context )) {
    listClicks.add( ds.getPropertyValue("agname") )
    }

    Thanks,
    Mikhail
  • Hi Marcus,
    Thanks for your response.
    But I could not find enough documentation regarding Next method by this this link.
    Could you please give an example how Next method works and what should I use as third parameter.

    Thanks,
    Mikhail
  • Hi,
    I have a number of values (>6500) which getting from SOAP response and need to sum up them.
    Before I have used Groovy script to parsing values from XML to List and then summarize, but it is taking very long time.
    Data Source allows to handle it and get collection much faster, but I don't know how to sum up values from Data Source.
    Is there any other way to summarize values from SOAP response in Soap UI?

    Thanks,
    Mikhail
  • questsbymun's avatar
    questsbymun
    Frequent Visitor

    Hi Abhinav,

     

    Has your question every been answered?  I am running into the same problem.  Googled the soupui api library (https://www.soapui.org/apidocs/pro/com/eviware/soapui/impl/wsdl/teststeps/WsdlDataSourceTestStep.html), but it's not very descriptive of what each methods does.  Every time I run my groovy script, which use the same code as yours, it only return me the last item on the list even thought the rows count was 8.   I have tried all the following methods to try to reset back to the 1st row in the Datasource, but without any luck!  

     

    repositionAtStartRow(com.eviware.soapui.model.testsuite.TestCaseRunner testRunner, com.eviware.soapui.model.testsuite.TestCaseRunContext context) 

     

    restart(com.eviware.soapui.model.testsuite.TestCaseRunner testRunner, com.eviware.soapui.model.testsuite.TestCaseRunContext context) 

     

    setStartRow(String startRow)   --> with startRow = "1"

     

     

    Mun