Interview Questions

Randomizing DataSource rows


(Continued from previous question...)

Randomizing DataSource rows

There is no built in support for DataSources fetching random rows in SoapUI, but this can be achieved with some scripting. Structure your TestCase like this:


The TestSteps should contain the following:
Original DataSource

A DataSource test step for the actual data that you want to randomize. Use this as you would normally.
Collect row
1.// create list if necessary
2.if( context["allRows"] == null ) context["allRows"] = []
4.// append current row from Original Source to allRows
5.context["allRows"] << context.expand( '${Original Source#output}' )

Original loop

DataSource Loop that loops to Collect row (Target Step) for each row in Original Source (DataSource Step).
Shuffle collected rows

1.Collections.shuffle( context["allRows"] )
Groovy DataSource
view sourceprint?
1.def row = testRunner.testCase.testSteps["Groovy DataSource"].currentRow 2.
3.if ( row + 1 <= context["allRows"].size() )
5. result["randomRow"] = context["allRows"][row]

Groovy DataSource loop
DataSource Loop that loops to the first test step using the random data (Target Step) for each row in Groovy DataSource (DataSource Step).

(Continued on next question...)

Other Interview Questions