Eviware Forum

soapUI => soapUI => Topic started by: Jon on June 02, 2008, 07:02:29 pm



Title: Groovy Datasource
Post by: Jon on June 02, 2008, 07:02:29 pm
Hi!

Trying to use a groovy datasource to generate some test values (to eliminate a spreadsheet containing just a column of numbers).

I need to iterate over that column, changing the values each time an outer loop increments.

What I have is this: a groovy datasource with a single property defined.  NExt, I have this script which takes two TestCase properties as the base from which to compute the list of values:

Code:
def numNetPortsPerTSStr = context.expand( '${#TestCase#numNetPortsPerTS}' )
def startNetPortStr = context.expand( '${#TestCase#startNetPort}' )

def numNetPortsPerTS = Integer.parseInt(numNetPortsPerTSStr)
def startNetPort = Integer.parseInt(startNetPortStr)

def i = 0

while (i < numNetPortsPerTS)
{
result.netPort = startNetPort + i
i++
}

The startNetPort is set to 1000 and numNetPortsPerTS is set to 10.

However, running this only gives me the same value (1009).  As well, trying to access the property, like so:

Code:
def netPortStr = context.expand( '${Net Port Datasource#netPort}' )
println "netPortStr:"+netPortStr

from another test step (groovy script) results in:

Mon Jun 02 13:53:51 EDT 2008:ERROR:java.lang.NumberFormatException: For input string: ""

The notes for the groovy datasource didn't help me out much so I'm hoping you can shed some light.

Cheers!


Title: Re: Groovy Datasource
Post by: omatzura on June 03, 2008, 03:05:34 pm
Hi!

I'm not sure if you really need a Groovy DataSource for this, how about the following:

1) an initial Script that writes the first value to the context
2-X) any numbers of steps that use the value
last) a script that increases the value in the context and loops back to 2 if the limit hasn't been reached

would that work?

regards,

/Ole
eviware.com


Title: Re: Groovy Datasource
Post by: Jon on June 03, 2008, 03:08:57 pm
Hey Ole,

That's a great idea, one which I'd thought of using at one point, but I couldn't figure out how to go back to a given step.  The conditional goto uses xpath and the datasource loop requires a datasource to increment.

Cheers!
Jon


Title: Re: Groovy Datasource
Post by: omatzura on June 03, 2008, 03:12:29 pm
Hi Jon,

you can use

testRunner.gotoStepByName( ... )

which will transfer execution to the named step when the script finishes (not at once!)

regards,

/Ole
eviware.com


Title: Re: Groovy Datasource
Post by: Jon on June 03, 2008, 03:38:24 pm
Cool!  I will give that a try, thanks!


Title: Re: Groovy Datasource
Post by: Jon on June 09, 2008, 07:05:38 pm
Hey Ole,

Just wanted to say thank you... these suggestions worked out quite well in the end.  Nice to not have to use an external file for everything.  :)

Cheers!


Title: Re: Groovy Datasource
Post by: omatzura on June 09, 2008, 09:23:31 pm
Great! Thanks for following up!

regards,

/Ole
eviware.com