Discussion:
BSF Scripts and User Defined Variables
S.D.
2009-07-16 17:59:38 UTC
Permalink
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
Deepak Shetty
2009-07-16 18:06:15 UTC
Permalink
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
Post by S.D.
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
${__BeanShell(${RANDOM_NAME})}.
"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
---------------------------------------------------------------------
Deepak Shetty
2009-07-16 18:27:45 UTC
Permalink
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
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
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 ..
Post by Deepak Shetty
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
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
${__BeanShell(${RANDOM_NAME})}.
"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
---------------------------------------------------------------------
S.D.
2009-07-16 19:01:18 UTC
Permalink
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.
Post by Deepak Shetty
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
Deepak Shetty
2009-07-16 20:30:21 UTC
Permalink
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
Post by S.D.
I apologize .. but I must be missing something very basic here. As you
return "this is a test";
name=GUID value=${__BeanShell(source("function.bsh"))}
name=JMETER_ID value=${GUID}
JMETER_ID: ${__BeanShell(source("function.bsh"))}
Thanks again for any insight.
Post by Deepak Shetty
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
---------------------------------------------------------------------
S.D.
2009-07-17 14:27:39 UTC
Permalink
Thank you for your help ! My jar files were in the wrong place. Once I
figured it out it worked fine.
Post by Deepak Shetty
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
Loading...