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/03/19 15:36:57 UTC

About BeanShell

Hello,

While developing a test script, I find that I need to quite some scripting, which can be done, but the user manual is not very verbose regarding this topic (as far as I can see). Currently, some very practical questions I have:
* suppose I created a set of functions in an external script file - how to call these from my script
* for this same file: when running in GUI-mode, how to ensure the JMeter has seen these function definitions?
* Section 16.8 shortly has some 'best practices', where it is mentioned that I can 'save a script as a variable' - what does that mean? How do I achieve that? My first guess was to copy/paste the function definition into the 'Value' column of a User Defined Variable in the Test Plan, but somehow that completely confuses the interpreter

Sincerely,
Jakob van Bethlehem
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: About BeanShell

Posted by Jitesh Thakur <th...@gmail.com>.
That's a very good method to script, another way is to use JSR223 sampler
/Pre-Postprocessor and use any coding language to write your script (I
prefer beanshell). You can call your script here and use different
variables in parameters field which you can use in your script using args[]
array and functions.

On 20 March 2013 11:58, Adrian Speteanu <as...@gmail.com> wrote:

> +1 for last part...
>
> Its a great method to setup your script file in the same element with all
> the other static variables (so you can make all changes in a single place.)
>
> On Wed, Mar 20, 2013 at 2:34 AM, Stott, Charlie <CS...@tnsi.com> wrote:
>
> > Hi Jakob,
> >
> > > * suppose I created a set of functions in an external script file - how
> > to call
> > > these from my script
> >
> > a) Read the file into a variable, then 'run' the variable using
> > __javaScript function.
> >
> > Or
> >
> > b) Use the beanshell pre-processor and enter the filename in the 'Script
> > file' field.
> >
> > > * for this same file: when running in GUI-mode, how to ensure the
> JMeter
> > > has seen these function definitions?
> >
> > Non-GUI uses the same test plan, not sure what problem you envisage here?
> >
> > > * Section 16.8 shortly has some 'best practices', where it is mentioned
> > that I
> > > can 'save a script as a variable' - what does that mean? How do I
> achieve
> > > that? My first guess was to copy/paste the function definition into the
> > 'Value'
> > > column of a User Defined Variable in the Test Plan, but somehow that
> > > completely confuses the interpreter
> >
> > Almost..
> >
> > For example, using User Defined Variables:
> >
> > Name:                           Value:
> > SCRIPT_VAR                      if ("${SOME_VAR" != "") {
> > vars.put("SOME_VAR", "value");}
> >
> > Then in another User Defined Variables element (scope means it won't run
> > in the same element):
> >
> > Name:                           Value:
> > RUN_SCRIPT                      ${__javaScript(${SCRIPT_VAR})}
> >
> > I tend to set the scripts early in my test plan, and then invoke them
> > where necessary.
> >
> > Hope that helps.
> > Charlie
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> > For additional commands, e-mail: user-help@jmeter.apache.org
> >
> >
>



-- 
*********************************************
Warm Regards
Jitesh Thakur (PMP, ISEB, CSQA)
http://in.linkedin.com/in/jiteshthakur
M: 07943464906
*********************************************

Re: About BeanShell

Posted by Adrian Speteanu <as...@gmail.com>.
+1 for last part...

Its a great method to setup your script file in the same element with all
the other static variables (so you can make all changes in a single place.)

On Wed, Mar 20, 2013 at 2:34 AM, Stott, Charlie <CS...@tnsi.com> wrote:

> Hi Jakob,
>
> > * suppose I created a set of functions in an external script file - how
> to call
> > these from my script
>
> a) Read the file into a variable, then 'run' the variable using
> __javaScript function.
>
> Or
>
> b) Use the beanshell pre-processor and enter the filename in the 'Script
> file' field.
>
> > * for this same file: when running in GUI-mode, how to ensure the JMeter
> > has seen these function definitions?
>
> Non-GUI uses the same test plan, not sure what problem you envisage here?
>
> > * Section 16.8 shortly has some 'best practices', where it is mentioned
> that I
> > can 'save a script as a variable' - what does that mean? How do I achieve
> > that? My first guess was to copy/paste the function definition into the
> 'Value'
> > column of a User Defined Variable in the Test Plan, but somehow that
> > completely confuses the interpreter
>
> Almost..
>
> For example, using User Defined Variables:
>
> Name:                           Value:
> SCRIPT_VAR                      if ("${SOME_VAR" != "") {
> vars.put("SOME_VAR", "value");}
>
> Then in another User Defined Variables element (scope means it won't run
> in the same element):
>
> Name:                           Value:
> RUN_SCRIPT                      ${__javaScript(${SCRIPT_VAR})}
>
> I tend to set the scripts early in my test plan, and then invoke them
> where necessary.
>
> Hope that helps.
> Charlie
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>

RE: About BeanShell

Posted by "Stott, Charlie" <CS...@tnsi.com>.
Hi Jakob,

> * suppose I created a set of functions in an external script file - how to call
> these from my script

a) Read the file into a variable, then 'run' the variable using __javaScript function.

Or

b) Use the beanshell pre-processor and enter the filename in the 'Script file' field.

> * for this same file: when running in GUI-mode, how to ensure the JMeter
> has seen these function definitions?

Non-GUI uses the same test plan, not sure what problem you envisage here?

> * Section 16.8 shortly has some 'best practices', where it is mentioned that I
> can 'save a script as a variable' - what does that mean? How do I achieve
> that? My first guess was to copy/paste the function definition into the 'Value'
> column of a User Defined Variable in the Test Plan, but somehow that
> completely confuses the interpreter

Almost..

For example, using User Defined Variables:

Name:				Value:
SCRIPT_VAR			if ("${SOME_VAR" != "") { vars.put("SOME_VAR", "value");}

Then in another User Defined Variables element (scope means it won't run in the same element):

Name:				Value:
RUN_SCRIPT			${__javaScript(${SCRIPT_VAR})}

I tend to set the scripts early in my test plan, and then invoke them where necessary.

Hope that helps.
Charlie

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org