Forum Discussion

sushant99's avatar
sushant99
Occasional Contributor
16 years ago

capturing array element values in a datasink

Hi there,

I want to capture the information comprised within two string arrays of a groovy assertion script to a DataSink report.

string array1 = ['Vehicle is of type Car', 'Vehicle is of type Scooter', 'Vehicle is of type Truck']
Column1 of the datasink report should have

Vehicle is of type Car
Vehicle is of type Scooter
Vehicle is of type Truck

string array2 = ['Vehicle is of type Cycle', 'Vehicle is of type Bike', 'Vehicle is of type Van']
Column2 of the datasink report should have

Vehicle is of type Cycle
Vehicle is of type Bike
Vehicle is of type Van


The datasink property does not seem to accept an array type. How can I get the above working.
Regards,
Sushant

1 Reply

  • Hello,

    It seems to me like you wish to run the DataSink a total of three times, once for each row you wish to enter. If this is the case, then you need to manually run the DataSink TestStep using a groovy script. You can try the following:

    First, disable the DataSink TestStep. Since we will be running it manually inside a loop, we do not with it to be run by the soapUI TestRunner as well. If you do not disable the step, the last row will be added twice.

    Second, modify the groovy script to run the DataSink with each row:


    ...

    string array1 = ['Vehicle is of type Car', 'Vehicle is of type Scooter', 'Vehicle is of type Truck']
    string array2 = ['Vehicle is of type Cycle', 'Vehicle is of type Bike', 'Vehicle is of type Van']

    def sink = testRunner.testCase.testSteps['DataSink'] //Replace with the name of your DataSink TestStep
    for( i in 0..array1.size ) {
    sink.properties['prop1'].value = array1[i] //Replace prop1 with the column name you're using in the TestStep
    sink.properties['prop2'].value = array2[i] //Replace prop2 with the column name you're using in the TestStep
    testRunner.runTestStepByName('DataSink') //Replace with the name of your DataSink TestStep
    }


    Hope this helps!

    Regards,
    Dain
    eviware.com