You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Jakob van Bethlehem <ja...@jet-stream.nl> on 2013/04/04 14:15:06 UTC

Again BeanShell

Dear users,

Previously I have been asking about this topic, but I can't quite wrap my head around it, I'm sure I'm missing something obvious, but maybe it helps to be very specific. 
For my testscript I need to 'calculate' some parameter values that are to be sent to the application I'm testing (ie: I'm creating HTTP Requests http://host?par1=val1&par2=val2 etc, and the val1 and val2 need to be calculated based on a set of arguments)

From what I get from the manuals, it should be possible to script the calculating functions in BeanShell in a single file, say 'myscripts.bsh', read these functions into JMeter once at the start of the script, and call these functions with their appropriate arguments when creating a HTTP Request:
* is this indeed a possible route to take? Or is there another way that is preferred?
* if yes: how to ensure that I read the BeanShell script only once at startup? In other words: which component to add as a child of which component in the testplan? Or maybe is it better to add a User Defined Variable to the test plain with the value of __BeanShell(source('myscripts.bsh'))?
* Once loaded: how to access a specific function from that file and how to pass arguments to that function? I have seen examples that define a variable BSSCRIPT as ${__BeanShell(source('myscripts.bsh'))} and then call this script as ${BSSCRIPT}. However, that would run the whole script, whereas I wish to call a specific function _in_ that script, and on top of that, to pass variables to that function 

To say the same in other words: in sect 19.5.13 on http://jmeter.apache.org/usermanual/functions.html there is a reference to the BeanShellFunction.bshrc, but it is not explained how to call for instance the getprop() function that is defined there, and how to pass specific values to that function. I'm looking for just how to achieve that, with the addition that I'd like my testscript to explicitly read my BeanShell script file (once) at the start of the test instead of configuring it as beanshell.function.init.

Hopefully I've been precize enough for people to point out what probably is quite obvious :P

Yours sincerely,
Jakob van Bethlehem

Re: Again BeanShell

Posted by Deepak Shetty <sh...@gmail.com>.
>it should be possible to script the calculating functions in BeanShell in
a single file, say 'myscripts.bsh', read these functions into JMeter once
>at the start of the script, and call these functions with their
appropriate arguments when creating a HTTP Request:

See beanshell.function.init defined in jmeter.properties- you can define
your functions here. In order to invoke it use
${__BeanShell(functionName("parameter"))
But I dont know whether this gets loaded "once" - As far as I could tell
from the docs the interpreter isnt shared between threads - so at minimum
it would load as many threads there are - but why does it matter to you? if
its because you care about your jmeter footprint then you are better off
writing custom functions i guess  (of which you can find examples in Jmeter
src or google)


regards
deepak



On Thu, Apr 4, 2013 at 5:15 AM, Jakob van Bethlehem <ja...@jet-stream.nl>wrote:

> Dear users,
>
> Previously I have been asking about this topic, but I can't quite wrap my
> head around it, I'm sure I'm missing something obvious, but maybe it helps
> to be very specific.
> For my testscript I need to 'calculate' some parameter values that are to
> be sent to the application I'm testing (ie: I'm creating HTTP Requests
> http://host?par1=val1&par2=val2 etc, and the val1 and val2 need to be
> calculated based on a set of arguments)
>
> From what I get from the manuals, it should be possible to script the
> calculating functions in BeanShell in a single file, say 'myscripts.bsh',
> read these functions into JMeter once at the start of the script, and call
> these functions with their appropriate arguments when creating a HTTP
> Request:
> * is this indeed a possible route to take? Or is there another way that is
> preferred?
> * if yes: how to ensure that I read the BeanShell script only once at
> startup? In other words: which component to add as a child of which
> component in the testplan? Or maybe is it better to add a User Defined
> Variable to the test plain with the value of
> __BeanShell(source('myscripts.bsh'))?
> * Once loaded: how to access a specific function from that file and how to
> pass arguments to that function? I have seen examples that define a
> variable BSSCRIPT as ${__BeanShell(source('myscripts.bsh'))} and then call
> this script as ${BSSCRIPT}. However, that would run the whole script,
> whereas I wish to call a specific function _in_ that script, and on top of
> that, to pass variables to that function
>
> To say the same in other words: in sect 19.5.13 on
> http://jmeter.apache.org/usermanual/functions.html there is a reference
> to the BeanShellFunction.bshrc, but it is not explained how to call for
> instance the getprop() function that is defined there, and how to pass
> specific values to that function. I'm looking for just how to achieve that,
> with the addition that I'd like my testscript to explicitly read my
> BeanShell script file (once) at the start of the test instead of
> configuring it as beanshell.function.init.
>
> Hopefully I've been precize enough for people to point out what probably
> is quite obvious :P
>
> Yours sincerely,
> Jakob van Bethlehem