Forum Discussion

LZhang's avatar
LZhang
Frequent Contributor
15 years ago

From property to datasource

Hi:

Is there a quick way to transfer all values from a property step to a datasource grid?

Regards,
Li Zhang

5 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Li,

    you would need to do this with groovy, do you want an example?

    regards,

    /Ole
    eviware.com
  • LZhang's avatar
    LZhang
    Frequent Contributor
    Hi:

    I have a property step in which it stores only StartDate (14 rows total).  The value for each StartDate is in UTC format:  2009-06-24T13:58:26Z.  My goal is to transfer all these 14 StartDate
    into the next step which is a datasource Grid type so I can loop this datasource later.  The 14 StartDates are in increment:
    2009-06-24T13:58:26Z
    2009-06-25T13:58:26Z
    2009-06-26T13:58:26Z
    2009-06-27T13:58:26Z
    2009-06-28T13:58:26Z
    .....

    That's why I need a datasource to loop.  Please provide me with an example how I can accomplish this.  Thank you.

    Li
  • LZhang's avatar
    LZhang
    Frequent Contributor
    Currently, I found an indirect way to do this, i.e, to output all the startDate to an external file using groovy and then in the next Datasource step, read those startDate back in as file and store them in
    the datasource. 

    I just wonder if there's a quicker/better way of doing this transfer between Property step and Datasource.

    Thanks,
    Li
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    I wrote a script that allows you to directly modify the Grid DataSource from Groovy:


    model = testRunner.testCase.testSteps['DataSource'].dataSource.gridModel

    def appendRow(String... data) {
    def row = model.rowCount - 1
    for(i in 0..(data.length-1)) {
    model.setValueAt(data[i], row, i)
    }
    }


    //Clear the grid
    model.deleteRows(0..(model.rowCount-1) as int[])

    //Insert data
    appendRow('Hello', 'World')
    appendRow('Goodbye', 'Moon')


    Replace the first line with one that correctly targets your Datasource.

    To use this the Grid DataSource needs to have the proper columns set up ahead of time. Each call to appendRow takes a number of Strings, at most the same number as there are columns available. Hope this helps!

    Regards,
    Dain
    eviware.com