16 years ago
New Runner - CSV
I would like to create a new Runner that would load a random line from a CSV file on each iteration, and then run it just like the Web Page Runner does now. This is probably undocumented, but poss...
import com.eviware.loadui.api.events.PropertyEvent
createProperty( 'file', File, null )
createProperty( 'mode', String, 'Random' )
createInput( "input", "Incoming Messages" )
createOutput( "output", "Outgoing Messages" )
def values = file.value == null ? [] : file.value.readLines()
addEventListener( PropertyEvent ) { event ->
if ( event.event == PropertyEvent.Event.VALUE ) {
if( event.property == file ) {
values = file.value == null ? [] : file.value.readLines()
}
}
}
onMessage = { incoming, outgoing, message ->
if( values.size > 0 )
{
def url = ''
if( mode.value == 'Random' )
url = getNextRandom()
else if( mode.value == 'Sequential' )
url = getNextSequential()
if( url != null && url.length() > 0 )
message['URL'] = url
}
send( output, message )
}
getNextRandom =
{
def index = (int)( Math.random()*(float)values.size )
return values[index]
}
def currentIndex = 0
getNextSequential =
{
if( currentIndex >= values.size )
currentIndex = 0
return values[currentIndex++]
}
layout {
property( property:mode, label:'Mode', options:['Random','Sequential'] )
separator(vertical:true)
property( property:file, label:"File", constraints: 'w 200!', style: '-fx-font-size: 13pt' )
}