jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Melnyk <melnykena...@gmail.com>
Subject BeanShell PreProcessor question
Date Mon, 29 Mar 2010 15:56:21 GMT
Gentlemen,

I'm seeing an interesting issue I have following code in the
BeanShellPreProcessor :

The idea is to get new random word every time from the array

// array of Strings
String[] args={"Test", "Test1","Test2"};

// This is an random element i'm going to extract from the array
int randomElement = (int)(Math.random() * (args.length - 1));

// This is just for debugging purpose, initialization of test plan variable
vars.put("randomElement", randomElement.toString());

// randomword i'll use in some search scenarios
vars.put("randomword", args[randomElement] );

What i have as result of the code above:

After the BeanShellPreProcessor is executed my variables looks(from Debug
Sampler):

randomElement=1
randomword=Test1 ,  OK that is what i was looking for

Then in my scripts randomword is used three times in search scenarios:

In first two searches referencing to randomword results a "Test1" string
which is OK but in the third search instead of "Test1" I'm seeing "Test" can
anyone explain why this happens? Or there is something wrong in
implementation?

-- 
Regards,
Andriy

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message