You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by "S.D." <si...@gmail.com> on 2009/07/16 19:59:38 UTC

BSF Scripts and User Defined Variables

Hello.

I am a little confused by how to use the BSF Sampler.  I'm hoping
someone can assist. I'm either misunderstanding the documentation or am
just not setting it up correctly.

I have a BSF Sampler that is attached to a groovy script file. The
sampler runs fine and I see the response.

I want to capture this response and include it in the Http header with
my test case.

I'm not sure how this is supposed to work.  I have a UDV, titled "GUID"
and its set to ${__BeanShell(${RANDOM_NAME})}."  In my Http Headers, I
have a header that is set to ${GUID} but I always see the full string:
${__BeanShell(${RANDOM_NAME})}.

In the JMeter doc, it states:

"Once the script is working properly, it can be stored as a variable on
the Test Plan. The script variable can then be used to create the
function call. For example, suppose a BeanShell script is stored in the
variable RANDOM_NAME. The function call can then be coded as
${__BeanShell(${RANDOM_NAME})}."

What is RANDOM_NAME ?  The name of the groovy script file?  Is there a
particular way I need to structure my script?  Does it only work for
BeanShell scripts (.bsh) ?  Is the name a filename or something else?
Does it have to be a PreProcessor or PostProcessor or Assertion?

Any assistance is much appreciated.

Thanks,
--sidd



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


Re: BSF Scripts and User Defined Variables

Posted by "S.D." <si...@gmail.com>.
Thank you for your help !  My jar files were in the wrong place.  Once I
figured it out it worked fine.

On Thu, 2009-07-16 at 13:30 -0700, Deepak Shetty wrote:
> Hi
> I believe the .bsh file should be in the bin directory . check your
> jmeter.log for errors
> This is the Structure I have and it seems to work
> Thread Group
>    Http Request
>      HTTPHeaderManager
>         val1 ${GUID}
>    User Defined Variables
>         GUID ${__BeanShell(source("function.bsh"))}
> 
> What version of JMeter are you using?
> regards
> deepak
> 

> 


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


Re: BSF Scripts and User Defined Variables

Posted by Deepak Shetty <sh...@gmail.com>.
Hi
I believe the .bsh file should be in the bin directory . check your
jmeter.log for errors
This is the Structure I have and it seems to work
Thread Group
   Http Request
     HTTPHeaderManager
        val1 ${GUID}
   User Defined Variables
        GUID ${__BeanShell(source("function.bsh"))}

What version of JMeter are you using?
regards
deepak

On Thu, Jul 16, 2009 at 12:01 PM, S.D. <si...@gmail.com> wrote:

> I apologize .. but I must be missing something very basic here.  As you
> can see I'm just trying to see it work:
>
> This is my function.bsh.  It is in the same directory as the jmeter jmx:
> return "this is a test";
>
> This is the GUID user defined variable:
> name=GUID value=${__BeanShell(source("function.bsh"))}
>
> This is in the JMETER_ID in the Http Headers:
> name=JMETER_ID value=${GUID}
>
> All I ever see in the response is this:
> JMETER_ID: ${__BeanShell(source("function.bsh"))}
>
> Thanks again for any insight.
>
> On Thu, 2009-07-16 at 11:27 -0700, Deepak Shetty wrote:
> > Also note that (from docs)
> >
> > ${__BeanShell(source("function.bsh"))} - processes the script in
> > function.bsh
> > is what you'd probably use to run a script...
> > regards
> > deepak
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: BSF Scripts and User Defined Variables

Posted by "S.D." <si...@gmail.com>.
I apologize .. but I must be missing something very basic here.  As you
can see I'm just trying to see it work:

This is my function.bsh.  It is in the same directory as the jmeter jmx:
return "this is a test";

This is the GUID user defined variable:
name=GUID value=${__BeanShell(source("function.bsh"))}

This is in the JMETER_ID in the Http Headers:
name=JMETER_ID value=${GUID}

All I ever see in the response is this:
JMETER_ID: ${__BeanShell(source("function.bsh"))}

Thanks again for any insight.

On Thu, 2009-07-16 at 11:27 -0700, Deepak Shetty wrote:
> Also note that (from docs)
> 
> ${__BeanShell(source("function.bsh"))} - processes the script in
> function.bsh
> is what you'd probably use to run a script...
> regards
> deepak



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


Re: BSF Scripts and User Defined Variables

Posted by Deepak Shetty <sh...@gmail.com>.
Also note that (from docs)

${__BeanShell(source("function.bsh"))} - processes the script in
function.bsh
is what you'd probably use to run a script...
regards
deepak



On Thu, Jul 16, 2009 at 11:23 AM, Deepak Shetty <sh...@gmail.com> wrote:

> Hi
> >You mean that RANDOM_NAME contains actual beanshell code?
> Yes.
> >Does it matter that it's Groovy code in a file?
> Never tried it , I dont think it will work. The __Beanshell is only for
> beanshell scripts.
> >And vars.put("GUID", YOURCALCULATEDVALUE) goes where?
> In your  Groovy script. You can remove the UDV defn. Once you add a value
> in vars, its available in Jmeter as  ${GUID} or vars.get("GUID"). This wont
> be the same for every iteration , as the code would get executed every
> iteration , presumably updating the value. You can see the variables
> available to your script in the sampler..
> regards
> deepak
>
>
> On Thu, Jul 16, 2009 at 11:16 AM, S.D. <si...@gmail.com> wrote:
>
>> Hi ..
>>
>> I'm not sure I understand what you mean .. You mean that RANDOM_NAME
>> contains actual beanshell code?  Does it matter that it's Groovy code in
>> a file?  Can you provide a simple example so I can just see something
>> working?
>>
>> And vars.put("GUID", YOURCALCULATEDVALUE) goes where?  In the value for
>> the UDV ?  If that's the case, wouldn't it be the same thing for every
>> iteration?  What would be the difference between this and just
>> hard-coding something?
>>
>> Thanks ..
>>
>> On Thu, 2009-07-16 at 11:06 -0700, Deepak Shetty wrote:
>> > In the documentation
>> > RANDOM_NAME is a variable whose value is the actual script contents
>> > that you wish to run. (i.e. the code itself)
>> > If your sampler is working fine , why not just do
>> > vars.put("GUID", YOURCALCULATEDVALUE);
>> >
>> > regards
>> > deepak
>> >
>> > On Thu, Jul 16, 2009 at 10:59 AM, S.D. <si...@gmail.com> wrote:
>> >         Hello.
>> >
>> >         I am a little confused by how to use the BSF Sampler.  I'm
>> >         hoping
>> >         someone can assist. I'm either misunderstanding the
>> >         documentation or am
>> >         just not setting it up correctly.
>> >
>> >         I have a BSF Sampler that is attached to a groovy script file.
>> >         The
>> >         sampler runs fine and I see the response.
>> >
>> >         I want to capture this response and include it in the Http
>> >         header with
>> >         my test case.
>> >
>> >         I'm not sure how this is supposed to work.  I have a UDV,
>> >         titled "GUID"
>> >         and its set to ${__BeanShell(${RANDOM_NAME})}."  In my Http
>> >         Headers, I
>> >         have a header that is set to ${GUID} but I always see the full
>> >         string:
>> >         ${__BeanShell(${RANDOM_NAME})}.
>> >
>> >         In the JMeter doc, it states:
>> >
>> >         "Once the script is working properly, it can be stored as a
>> >         variable on
>> >         the Test Plan. The script variable can then be used to create
>> >         the
>> >         function call. For example, suppose a BeanShell script is
>> >         stored in the
>> >         variable RANDOM_NAME. The function call can then be coded as
>> >         ${__BeanShell(${RANDOM_NAME})}."
>> >
>> >         What is RANDOM_NAME ?  The name of the groovy script file?  Is
>> >         there a
>> >         particular way I need to structure my script?  Does it only
>> >         work for
>> >         BeanShell scripts (.bsh) ?  Is the name a filename or
>> >         something else?
>> >         Does it have to be a PreProcessor or PostProcessor or
>> >         Assertion?
>> >
>> >         Any assistance is much appreciated.
>> >
>> >         Thanks,
>> >         --sidd
>> >
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> >         To unsubscribe, e-mail:
>> >         jmeter-user-unsubscribe@jakarta.apache.org
>> >         For additional commands, e-mail:
>> >         jmeter-user-help@jakarta.apache.org
>> >
>> >
>>
>>
>

Re: BSF Scripts and User Defined Variables

Posted by Deepak Shetty <sh...@gmail.com>.
In the documentation
RANDOM_NAME is a variable whose value is the actual script contents that you
wish to run. (i.e. the code itself)
If your sampler is working fine , why not just do
vars.put("GUID", YOURCALCULATEDVALUE);

regards
deepak

On Thu, Jul 16, 2009 at 10:59 AM, S.D. <si...@gmail.com> wrote:

> Hello.
>
> I am a little confused by how to use the BSF Sampler.  I'm hoping
> someone can assist. I'm either misunderstanding the documentation or am
> just not setting it up correctly.
>
> I have a BSF Sampler that is attached to a groovy script file. The
> sampler runs fine and I see the response.
>
> I want to capture this response and include it in the Http header with
> my test case.
>
> I'm not sure how this is supposed to work.  I have a UDV, titled "GUID"
> and its set to ${__BeanShell(${RANDOM_NAME})}."  In my Http Headers, I
> have a header that is set to ${GUID} but I always see the full string:
> ${__BeanShell(${RANDOM_NAME})}.
>
> In the JMeter doc, it states:
>
> "Once the script is working properly, it can be stored as a variable on
> the Test Plan. The script variable can then be used to create the
> function call. For example, suppose a BeanShell script is stored in the
> variable RANDOM_NAME. The function call can then be coded as
> ${__BeanShell(${RANDOM_NAME})}."
>
> What is RANDOM_NAME ?  The name of the groovy script file?  Is there a
> particular way I need to structure my script?  Does it only work for
> BeanShell scripts (.bsh) ?  Is the name a filename or something else?
> Does it have to be a PreProcessor or PostProcessor or Assertion?
>
> Any assistance is much appreciated.
>
> Thanks,
> --sidd
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>