You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Bennett McElwee <Be...@telecom.co.nz> on 2006/02/22 22:31:37 UTC
Tip: Calling BeanShell code at arbitrary points
Here's a useful tip for gaining finer control over your test plans. In
particular, for including BeanShell code at arbitrary points in your
tests. I'd love to hear of any similar or better ideas from other JMeter
users.
If you want to call BeanShell code before each execution of a Sampler,
put the code into an external file and add a User Parameters
Pre-Processor to the Sampler. In the Pre-Processor, check "Update Once
Per Iteration", and add a single variable. The name of the variable can
be anything, and the value ("User_1") should be
${__BeanShell(source("BeanShellSourceFile.bsh");,)}
This allows you to do things such as recalculate variables within a
loop.
Calling BeanShell code after each execution of a Sampler is simpler.
Just put the code into a BeanShell Assertion attached to the Sampler. I
have used this for tweaking Sampler results before the listener writes
them to a file.
These are the best approaches I have found. I initially thought of
different approaches, but they weren't satisfactory:
- The BeanShell Sampler would be useful, except that it adds an extra
sample point in your results -- not so good if all you wanted it to do
was calculate a variable or write a log message.
- The User Defined Variables component could be used in the same manner
as the User Parameters Pre-Processor, but it doesn't work in loops since
it's not called every time.
What we really need is a BeanShell Pre-Processor and a BeanShell
Post-Processor. These would be extremely useful. In fact, if we could
get a BeanShell Timer and especially a BeanShell Listener too, JMeter
would make a giant leap in usefulness and flexibility.
Cheerio,
Bennett.
--
Bennett McElwee
This communication, including any attachments, is confidential. If you are not the intended recipient, you should not read it - please contact me immediately, destroy it, and do not copy or use any part of this communication or disclose anything about it. Thank you. Please note that this communication does not designate an information system for the purposes of the Electronic Transactions Act 2002.
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
Re: Tip: Calling BeanShell code at arbitrary points
Posted by sebb <se...@gmail.com>.
On 22/02/06, Bennett McElwee <Be...@telecom.co.nz> wrote:
> Here's a useful tip for gaining finer control over your test plans. In
> particular, for including BeanShell code at arbitrary points in your
> tests. I'd love to hear of any similar or better ideas from other JMeter
> users.
>
> If you want to call BeanShell code before each execution of a Sampler,
> put the code into an external file and add a User Parameters
> Pre-Processor to the Sampler. In the Pre-Processor, check "Update Once
> Per Iteration", and add a single variable. The name of the variable can
> be anything, and the value ("User_1") should be
> ${__BeanShell(source("BeanShellSourceFile.bsh");,)}
> This allows you to do things such as recalculate variables within a
> loop.
>
> Calling BeanShell code after each execution of a Sampler is simpler.
> Just put the code into a BeanShell Assertion attached to the Sampler. I
> have used this for tweaking Sampler results before the listener writes
> them to a file.
Neat.
> These are the best approaches I have found. I initially thought of
> different approaches, but they weren't satisfactory:
> - The BeanShell Sampler would be useful, except that it adds an extra
> sample point in your results -- not so good if all you wanted it to do
> was calculate a variable or write a log message.
> - The User Defined Variables component could be used in the same manner
> as the User Parameters Pre-Processor, but it doesn't work in loops since
> it's not called every time.
BTW, there are some properties that can be used to define initialisation files:
beanshell.sampler.init=BeanShellSampler.bshrc
beanshell.function.init=BeanShellFunction.bshrc
beanshell.assertion.init=etc
These can be used to set up methods etc.
> What we really need is a BeanShell Pre-Processor and a BeanShell
> Post-Processor. These would be extremely useful. In fact, if we could
> get a BeanShell Timer and especially a BeanShell Listener too, JMeter
> would make a giant leap in usefulness and flexibility.
When BeanShell was added it was not clear how much use would be made of it.
You've shown that some simple code can be very effective.
I'll see about adding the other BSH elements.
I don't think these would be too difficult.
Thanks for the great suggestions.
BTW, feel free (others too) to update the JMeter Wiki with all these good ideas.
S.
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org