You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Philip Peake <ph...@vogon.net> on 2006/09/23 03:03:26 UTC

Accessing regex variables in Beanshell

Jmeter 2.2

I am having problems picking up variables set by the Regular Expression 
Extractor in a Beanshell.

I have an HTTP Request sampler. Contained in the body of the page 
returned by this is the word "Squirrel".
As a child of the HTTP Request I have a Regular Expression Extractor 
(Post Processor) set up as follows:

Response Field:   <Body checked>
Reference Name:   FOO
Regular Expression:   (Squirrel)
Template:   $1
Default Value:   "Missed"

If I understand the documentation correctly, this should initialize a 
variable called FOO, accessible as ${FOO} which will contain "Squirrel" 
if that is present in the body of the response processed by the HTTP 
Request sampler, or "Missed" as a value if it is not.

Following the Regex, again as a child of the same HTTP Request sampler, 
I have a BeanShell PostProcessor.
This is where I am having difficulty. I cannot find a way to access the 
${FOO} variable.

If I try:

    print(${FOO});

I get this:

2006/09/22 17:58:59 ERROR - jmeter.util.BeanShellInterpreter: Error 
invoking bsh method eval
 java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at 
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
    at 
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
    at 
org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
    at 
org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
    at java.lang.Thread.run(Unknown Source)
Caused by: Sourced file: inline evaluation of: ``print(${FOO});'' : 
Attempt to access property on undefined variable or class name : at 
Line: 1 : in file: inline evaluation of: ``print(${FOO});'' : {

    at bsh.BSHPrimarySuffix.doProperty(Unknown Source)
    at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
    at bsh.BSHPrimaryExpression.eval(Unknown Source)
    at bsh.BSHPrimaryExpression.eval(Unknown Source)
    at bsh.BSHArguments.getArguments(Unknown Source)
    at bsh.BSHMethodInvocation.eval(Unknown Source)
    at bsh.BSHPrimaryExpression.eval(Unknown Source)
    at bsh.BSHPrimaryExpression.eval(Unknown Source)
    at bsh.Interpreter.eval(Unknown Source)
    at bsh.Interpreter.eval(Unknown Source)
    at bsh.Interpreter.eval(Unknown Source)
    ... 10 more

So, I tried this way:

s=vars.get("${FOO}");
print(s);

This prints out

     null

So how exactly do I access the variable FOO set in the preceeding 
(regex) post processor???

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


Re: Accessing regex variables in Beanshell

Posted by sebb <se...@gmail.com>.
Indeed - but the variable would still be set, either to "$1" or to "Missed".

On 25/09/06, Marc Anthony Winoto <ma...@netregistry.com.au> wrote:
> I have the same setup. Regex Extractor followed by a BeanShell PreProc.
>
> The difference between mine and your example below is that my template is $1$ for the first
> match. Putting $1 in it's place breaks everything.
>
> I just checked the docs, and it also says $1$ is correct.
>
> Philip Peake wrote:
> >>     Response Field:   <Body checked>
> >>     Reference Name:   FOO
> >>     Regular Expression:   (Squirrel)
> >>     Template:   $1
> >>     Default Value:   "Missed"
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

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


Re: Accessing regex variables in Beanshell

Posted by Marc Anthony Winoto <ma...@netregistry.com.au>.
I have the same setup. Regex Extractor followed by a BeanShell PreProc.

The difference between mine and your example below is that my template is $1$ for the first 
match. Putting $1 in it's place breaks everything.

I just checked the docs, and it also says $1$ is correct.

Philip Peake wrote:
>>     Response Field:   <Body checked>
>>     Reference Name:   FOO
>>     Regular Expression:   (Squirrel)
>>     Template:   $1
>>     Default Value:   "Missed"
>>

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


Re: How do I use print() with variables?

Posted by sebb <se...@gmail.com>.
On 26/09/06, Marc Anthony Winoto <ma...@netregistry.com.au> wrote:
> While trying to reproduce Philip's BeanShell problem, I found some strange behaviour.
>
> HTTP Sampler
> |
> |-Regex: test, (the), $1$, 1, "fout"
> |
> BeanShell PostProcessor or PreProcessor: print(${test}); or print(""+${test});

This would be interpreted as

print(the); or print(""+the);

which is not valid unless you define the BeanShell variable "the".

JMeter variables are replaced *before* the script is passed to Beanshell.

To print a JMeter variable in BeanShell, you need to use:

print("${VAR}"); or print(vars.get("VAR"));

> |
> |
> HTTP Sampler: go to http://${test}
>
> The bean shell never got a value for test. I can print out hardcoded strings and predefined
> variables though.
>
> The 2nd HTTP sampler does get a correct value from the test variable and tries to go to
> http://the (and fails).
>
> I also tried putting the beanshell as a child of the first http sampler. Nothing. What's going on?

See also other thread - Post-Processors are run in reverse order
(don't know why yet).

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

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


How do I use print() with variables?

Posted by Marc Anthony Winoto <ma...@netregistry.com.au>.
While trying to reproduce Philip's BeanShell problem, I found some strange behaviour.

HTTP Sampler
|
|-Regex: test, (the), $1$, 1, "fout"
|
BeanShell PostProcessor or PreProcessor: print(${test}); or print(""+${test});
|
|
HTTP Sampler: go to http://${test}

The bean shell never got a value for test. I can print out hardcoded strings and predefined 
variables though.

The 2nd HTTP sampler does get a correct value from the test variable and tries to go to 
http://the (and fails).

I also tried putting the beanshell as a child of the first http sampler. Nothing. What's going on?

Marc

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


Re: Accessing regex variables in Beanshell

Posted by sebb <se...@gmail.com>.
The same behaviour occurred in JMeter 1.9.1.

That only had a single Post-Processor (the Regex Extractor) so the
order did not really matter.

I've not tried any earlier releases yet.

S.
On 26/09/06, sebb <se...@gmail.com> wrote:
> Very odd.
>
> I can confirm the behaviour; Post-Processors are run in the opposite
> order to what one expects.
>
> Looking at the code in JMeterThread.runPostProcessors() it actually
> traverses the list of post-processors in reverse order.  I've no idea
> why it does this - some further investigation is needed. Perhaps
> originally the post-processors were added to the list in reverse
> order?
>
> I need to check back with earlier releases to see what they did.
>
> S.
> On 26/09/06, Philip Peake <ph...@vogon.net> wrote:
> > Ok --- I found an answer. Not a particularly satisfactory one, but an
> > answer.
> > I became convinced that my "FOO" variable was just not getting set, and
> > that there was essentially nothing wrong with what I was trying to do in
> > the BeanShell - other than use an undefined variable.
> >
> > I added aUser Defined Variable config element, set FOO there and that
> > worked. So the variable is not getting set by the regex extractor. I
> > tried everything. Including reversing the order of the regex extractor
> > and the BeanShell -- guess what? That works.
> >
> > So I now have:
> >
> >     HTTP Request
> >        |
> >        -- BeanShell Postprocessor
> >        |
> >        -- Regular Expression Extractor
> >
> > And when the BeanShell runs, it has the value set by the regex extractor
> > - reverse them again and it fails.
> > Checking the testplan .jms file, the XML shows the elements in the order
> > they are displayed in the GUI, so its not simply a display problem.
> >
> > Anyone any clue why I have to have the elemet using the variable appear
> > before the element initializing that variable?
> >
> > Philip
> >
> > -------------------------------------------------------
> >
> > sebb wrote:
> > > On 25/09/06, Philip Peake <ph...@vogon.net> wrote:
> > >> Hmm... the variable is not defined ....
> > >> But going back to my original e-mail, I said:
> > >>
> > >> >     I have an HTTP Request sampler. Contained in the body of the page
> > >> >     returned by this is the word "Squirrel".
> > >> >     As a child of the HTTP Request I have a Regular Expression
> > >> >     Extractor (Post Processor) set up as follows:
> > >> >
> > >> >     Response Field:   <Body checked>
> > >> >     Reference Name:   FOO
> > >> >     Regular Expression:   (Squirrel)
> > >> >     Template:   $1
> > >
> > > As mentioned in another e-mail, this should be $1$
> > >
> > >> >     Default Value:   "Missed"
> > >> >
> > >> >     If I understand the documentation correctly, this should
> > >> >     initialize a variable called FOO, accessible as ${FOO} which will
> > >> >     contain "Squirrel" if that is present in the body of the response
> > >> >     processed by the HTTP Request sampler, or "Missed" as a value if
> > >> >     it is not.
> > >>
> > >> To which you replied:
> > >>
> > >> >     > If I understand the documentation correctly, this should
> > >> >     initialize a
> > >> >     > variable called FOO, accessible as ${FOO} which will contain
> > >> >     "Squirrel"
> > >> >     > if that is present in the body of the response processed by the
> > >> >     HTTP
> > >> >     > Request sampler, or "Missed" as a value if it is not.
> > >> >
> > >> >     Yes.
> > >>
> > >> So, which is it?
> > >
> > > The variable FOO will be set to the value of the template if the RE
> > > matches, otherwise the variable FOO will be set to "Missed".
> > >
> > > In your case, the value of the template was "$1", not "Squirrel", but
> > > the rules still apply.
> > >
> > >> Is it that variables defined in an imediately preceeding pos-processor
> > >> is not available in the next?
> > >
> > > The variables are available as soon as they have been defined, i.e. as
> > > soon as the post-processor has been run.
> > >
> > >> I am really trying to understand this....
> > >>
> > >> Philip
> > >>
> > >> -----------------------------------------------
> > >>
> > >>
> > >>
> > >> sebb wrote:
> > >>
> > >> > On 24/09/06, Philip Peake <ph...@vogon.net> wrote:
> > >> >
> > >> >> Thanks for pointing out that the ${VAR} variables are pre-processed.
> > >> >> So I tried this:
> > >> >>
> > >> >>     s=vars.get("FOO");
> > >> >>     print(s);
> > >> >>
> > >> >> It print out:
> > >> >>
> > >> >>     null
> > >> >
> > >> >
> > >> > i.e. FOO is not defined as a variable
> > >> >
> > >> >> I also tried:
> > >> >>
> > >> >>     s=${FOO};
> > >> >>     print(s);
> > >> >>
> > >> >> Which gave:
> > >> >>
> > >> >>     2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter:
> > >> Error
> > >> >>     invoking bsh method eval
> > >> >>      java.lang.reflect.InvocationTargetException
> > >> >>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > >> Method)
> > >> >>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
> > >> Source)
> > >> >>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> > >> >> Source)
> > >> >>         at java.lang.reflect.Method.invoke(Unknown Source)
> > >> >>         at
> > >> >>
> > >> >>
> > >> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
> > >>
> > >> >>
> > >> >>         at
> > >> >>
> > >> >>
> > >> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
> > >>
> > >> >>
> > >> >>         at
> > >> >>
> > >> >>
> > >> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
> > >>
> > >> >>
> > >> >>         at
> > >> >>
> > >> >>
> > >> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
> > >>
> > >> >>
> > >> >>         at
> > >> >> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
> > >> >>         at java.lang.Thread.run(Unknown Source)
> > >> >>     Caused by: Sourced file: inline evaluation of: ``s=${FOO};
> > >> print(s);
> > >> >>     ;'' : Attempt to access property on undefined variable or
> > >> class name
> > >> >>     : at Line: 1 : in file: inline evaluation of: ``s=${FOO};
> > >> print(s);
> > >> >>     ;'' : {
> > >> >
> > >> >
> > >> > ditto
> > >> >
> > >> >> And finally, I tried:
> > >> >>
> > >> >>     print("${FOO}");
> > >> >>
> > >> >> Which printed:
> > >> >>
> > >> >>     ${FOO}
> > >> >
> > >> >
> > >> > ditto
> > >> >
> > >> >> I still don't see how to do this ....
> > >> >>
> > >> >
> > >> > The above is correct, but the variable is not defined.
> > >> >
> > >> > ---------------------------------------------------------------------
> > >> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > >> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > >>
> > >>
> > >>
> > >>
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
>

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


Re: Accessing regex variables in Beanshell

Posted by sebb <se...@gmail.com>.
Very odd.

I can confirm the behaviour; Post-Processors are run in the opposite
order to what one expects.

Looking at the code in JMeterThread.runPostProcessors() it actually
traverses the list of post-processors in reverse order.  I've no idea
why it does this - some further investigation is needed. Perhaps
originally the post-processors were added to the list in reverse
order?

I need to check back with earlier releases to see what they did.

S.
On 26/09/06, Philip Peake <ph...@vogon.net> wrote:
> Ok --- I found an answer. Not a particularly satisfactory one, but an
> answer.
> I became convinced that my "FOO" variable was just not getting set, and
> that there was essentially nothing wrong with what I was trying to do in
> the BeanShell - other than use an undefined variable.
>
> I added aUser Defined Variable config element, set FOO there and that
> worked. So the variable is not getting set by the regex extractor. I
> tried everything. Including reversing the order of the regex extractor
> and the BeanShell -- guess what? That works.
>
> So I now have:
>
>     HTTP Request
>        |
>        -- BeanShell Postprocessor
>        |
>        -- Regular Expression Extractor
>
> And when the BeanShell runs, it has the value set by the regex extractor
> - reverse them again and it fails.
> Checking the testplan .jms file, the XML shows the elements in the order
> they are displayed in the GUI, so its not simply a display problem.
>
> Anyone any clue why I have to have the elemet using the variable appear
> before the element initializing that variable?
>
> Philip
>
> -------------------------------------------------------
>
> sebb wrote:
> > On 25/09/06, Philip Peake <ph...@vogon.net> wrote:
> >> Hmm... the variable is not defined ....
> >> But going back to my original e-mail, I said:
> >>
> >> >     I have an HTTP Request sampler. Contained in the body of the page
> >> >     returned by this is the word "Squirrel".
> >> >     As a child of the HTTP Request I have a Regular Expression
> >> >     Extractor (Post Processor) set up as follows:
> >> >
> >> >     Response Field:   <Body checked>
> >> >     Reference Name:   FOO
> >> >     Regular Expression:   (Squirrel)
> >> >     Template:   $1
> >
> > As mentioned in another e-mail, this should be $1$
> >
> >> >     Default Value:   "Missed"
> >> >
> >> >     If I understand the documentation correctly, this should
> >> >     initialize a variable called FOO, accessible as ${FOO} which will
> >> >     contain "Squirrel" if that is present in the body of the response
> >> >     processed by the HTTP Request sampler, or "Missed" as a value if
> >> >     it is not.
> >>
> >> To which you replied:
> >>
> >> >     > If I understand the documentation correctly, this should
> >> >     initialize a
> >> >     > variable called FOO, accessible as ${FOO} which will contain
> >> >     "Squirrel"
> >> >     > if that is present in the body of the response processed by the
> >> >     HTTP
> >> >     > Request sampler, or "Missed" as a value if it is not.
> >> >
> >> >     Yes.
> >>
> >> So, which is it?
> >
> > The variable FOO will be set to the value of the template if the RE
> > matches, otherwise the variable FOO will be set to "Missed".
> >
> > In your case, the value of the template was "$1", not "Squirrel", but
> > the rules still apply.
> >
> >> Is it that variables defined in an imediately preceeding pos-processor
> >> is not available in the next?
> >
> > The variables are available as soon as they have been defined, i.e. as
> > soon as the post-processor has been run.
> >
> >> I am really trying to understand this....
> >>
> >> Philip
> >>
> >> -----------------------------------------------
> >>
> >>
> >>
> >> sebb wrote:
> >>
> >> > On 24/09/06, Philip Peake <ph...@vogon.net> wrote:
> >> >
> >> >> Thanks for pointing out that the ${VAR} variables are pre-processed.
> >> >> So I tried this:
> >> >>
> >> >>     s=vars.get("FOO");
> >> >>     print(s);
> >> >>
> >> >> It print out:
> >> >>
> >> >>     null
> >> >
> >> >
> >> > i.e. FOO is not defined as a variable
> >> >
> >> >> I also tried:
> >> >>
> >> >>     s=${FOO};
> >> >>     print(s);
> >> >>
> >> >> Which gave:
> >> >>
> >> >>     2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter:
> >> Error
> >> >>     invoking bsh method eval
> >> >>      java.lang.reflect.InvocationTargetException
> >> >>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> >> Method)
> >> >>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
> >> Source)
> >> >>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> >> >> Source)
> >> >>         at java.lang.reflect.Method.invoke(Unknown Source)
> >> >>         at
> >> >>
> >> >>
> >> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
> >>
> >> >>
> >> >>         at
> >> >>
> >> >>
> >> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
> >>
> >> >>
> >> >>         at
> >> >>
> >> >>
> >> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
> >>
> >> >>
> >> >>         at
> >> >>
> >> >>
> >> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
> >>
> >> >>
> >> >>         at
> >> >> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
> >> >>         at java.lang.Thread.run(Unknown Source)
> >> >>     Caused by: Sourced file: inline evaluation of: ``s=${FOO};
> >> print(s);
> >> >>     ;'' : Attempt to access property on undefined variable or
> >> class name
> >> >>     : at Line: 1 : in file: inline evaluation of: ``s=${FOO};
> >> print(s);
> >> >>     ;'' : {
> >> >
> >> >
> >> > ditto
> >> >
> >> >> And finally, I tried:
> >> >>
> >> >>     print("${FOO}");
> >> >>
> >> >> Which printed:
> >> >>
> >> >>     ${FOO}
> >> >
> >> >
> >> > ditto
> >> >
> >> >> I still don't see how to do this ....
> >> >>
> >> >
> >> > The above is correct, but the variable is not defined.
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

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


Re: Accessing regex variables in Beanshell

Posted by Philip Peake <ph...@vogon.net>.
Ok --- I found an answer. Not a particularly satisfactory one, but an 
answer.
I became convinced that my "FOO" variable was just not getting set, and 
that there was essentially nothing wrong with what I was trying to do in 
the BeanShell - other than use an undefined variable.

I added aUser Defined Variable config element, set FOO there and that 
worked. So the variable is not getting set by the regex extractor. I 
tried everything. Including reversing the order of the regex extractor 
and the BeanShell -- guess what? That works.

So I now have:

    HTTP Request
       |
       -- BeanShell Postprocessor
       |
       -- Regular Expression Extractor

And when the BeanShell runs, it has the value set by the regex extractor 
- reverse them again and it fails.
Checking the testplan .jms file, the XML shows the elements in the order 
they are displayed in the GUI, so its not simply a display problem.

Anyone any clue why I have to have the elemet using the variable appear 
before the element initializing that variable?

Philip

-------------------------------------------------------

sebb wrote:
> On 25/09/06, Philip Peake <ph...@vogon.net> wrote:
>> Hmm... the variable is not defined ....
>> But going back to my original e-mail, I said:
>>
>> >     I have an HTTP Request sampler. Contained in the body of the page
>> >     returned by this is the word "Squirrel".
>> >     As a child of the HTTP Request I have a Regular Expression
>> >     Extractor (Post Processor) set up as follows:
>> >
>> >     Response Field:   <Body checked>
>> >     Reference Name:   FOO
>> >     Regular Expression:   (Squirrel)
>> >     Template:   $1
>
> As mentioned in another e-mail, this should be $1$
>
>> >     Default Value:   "Missed"
>> >
>> >     If I understand the documentation correctly, this should
>> >     initialize a variable called FOO, accessible as ${FOO} which will
>> >     contain "Squirrel" if that is present in the body of the response
>> >     processed by the HTTP Request sampler, or "Missed" as a value if
>> >     it is not.
>>
>> To which you replied:
>>
>> >     > If I understand the documentation correctly, this should
>> >     initialize a
>> >     > variable called FOO, accessible as ${FOO} which will contain
>> >     "Squirrel"
>> >     > if that is present in the body of the response processed by the
>> >     HTTP
>> >     > Request sampler, or "Missed" as a value if it is not.
>> >
>> >     Yes.
>>
>> So, which is it?
>
> The variable FOO will be set to the value of the template if the RE
> matches, otherwise the variable FOO will be set to "Missed".
>
> In your case, the value of the template was "$1", not "Squirrel", but
> the rules still apply.
>
>> Is it that variables defined in an imediately preceeding pos-processor
>> is not available in the next?
>
> The variables are available as soon as they have been defined, i.e. as
> soon as the post-processor has been run.
>
>> I am really trying to understand this....
>>
>> Philip
>>
>> -----------------------------------------------
>>
>>
>>
>> sebb wrote:
>>
>> > On 24/09/06, Philip Peake <ph...@vogon.net> wrote:
>> >
>> >> Thanks for pointing out that the ${VAR} variables are pre-processed.
>> >> So I tried this:
>> >>
>> >>     s=vars.get("FOO");
>> >>     print(s);
>> >>
>> >> It print out:
>> >>
>> >>     null
>> >
>> >
>> > i.e. FOO is not defined as a variable
>> >
>> >> I also tried:
>> >>
>> >>     s=${FOO};
>> >>     print(s);
>> >>
>> >> Which gave:
>> >>
>> >>     2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter: 
>> Error
>> >>     invoking bsh method eval
>> >>      java.lang.reflect.InvocationTargetException
>> >>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native 
>> Method)
>> >>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown 
>> Source)
>> >>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
>> >> Source)
>> >>         at java.lang.reflect.Method.invoke(Unknown Source)
>> >>         at
>> >>
>> >> 
>> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150) 
>>
>> >>
>> >>         at
>> >>
>> >> 
>> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186) 
>>
>> >>
>> >>         at
>> >>
>> >> 
>> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80) 
>>
>> >>
>> >>         at
>> >>
>> >> 
>> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428) 
>>
>> >>
>> >>         at
>> >> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
>> >>         at java.lang.Thread.run(Unknown Source)
>> >>     Caused by: Sourced file: inline evaluation of: ``s=${FOO}; 
>> print(s);
>> >>     ;'' : Attempt to access property on undefined variable or 
>> class name
>> >>     : at Line: 1 : in file: inline evaluation of: ``s=${FOO}; 
>> print(s);
>> >>     ;'' : {
>> >
>> >
>> > ditto
>> >
>> >> And finally, I tried:
>> >>
>> >>     print("${FOO}");
>> >>
>> >> Which printed:
>> >>
>> >>     ${FOO}
>> >
>> >
>> > ditto
>> >
>> >> I still don't see how to do this ....
>> >>
>> >
>> > The above is correct, but the variable is not defined.
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


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


Re: Accessing regex variables in Beanshell

Posted by Ravi Kiran <ra...@bnaindia.com>.
----- Original Message ----- 
From: "sebb" <se...@gmail.com>
To: "JMeter Users List" <jm...@jakarta.apache.org>
Sent: Monday, September 25, 2006 5:31 AM
Subject: Re: Accessing regex variables in Beanshell


> On 25/09/06, Philip Peake <ph...@vogon.net> wrote:
>> Hmm... the variable is not defined ....
>> But going back to my original e-mail, I said:
>>
>> >     I have an HTTP Request sampler. Contained in the body of the page
>> >     returned by this is the word "Squirrel".
>> >     As a child of the HTTP Request I have a Regular Expression
>> >     Extractor (Post Processor) set up as follows:
>> >
>> >     Response Field:   <Body checked>
>> >     Reference Name:   FOO
>> >     Regular Expression:   (Squirrel)
>> >     Template:   $1
hi use $0$ instead of $1 in the template field and check.


> As mentioned in another e-mail, this should be $1$
>
>> >     Default Value:   "Missed"
>> >
>> >     If I understand the documentation correctly, this should
>> >     initialize a variable called FOO, accessible as ${FOO} which will
>> >     contain "Squirrel" if that is present in the body of the response
>> >     processed by the HTTP Request sampler, or "Missed" as a value if
>> >     it is not.
>>
>> To which you replied:
>>
>> >     > If I understand the documentation correctly, this should
>> >     initialize a
>> >     > variable called FOO, accessible as ${FOO} which will contain
>> >     "Squirrel"
>> >     > if that is present in the body of the response processed by the
>> >     HTTP
>> >     > Request sampler, or "Missed" as a value if it is not.
>> >
>> >     Yes.
>>
>> So, which is it?
>
> The variable FOO will be set to the value of the template if the RE
> matches, otherwise the variable FOO will be set to "Missed".
>
> In your case, the value of the template was "$1", not "Squirrel", but
> the rules still apply.
>
>> Is it that variables defined in an imediately preceeding pos-processor
>> is not available in the next?
>
> The variables are available as soon as they have been defined, i.e. as
> soon as the post-processor has been run.
>
>> I am really trying to understand this....
>>
>> Philip
>>
>> -----------------------------------------------
>>
>>
>>
>> sebb wrote:
>>
>> > On 24/09/06, Philip Peake <ph...@vogon.net> wrote:
>> >
>> >> Thanks for pointing out that the ${VAR} variables are pre-processed.
>> >> So I tried this:
>> >>
>> >>     s=vars.get("FOO");
>> >>     print(s);
>> >>
>> >> It print out:
>> >>
>> >>     null
>> >
>> >
>> > i.e. FOO is not defined as a variable
>> >
>> >> I also tried:
>> >>
>> >>     s=${FOO};
>> >>     print(s);
>> >>
>> >> Which gave:
>> >>
>> >>     2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter: 
>> >> Error
>> >>     invoking bsh method eval
>> >>      java.lang.reflect.InvocationTargetException
>> >>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> >>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
>> >> Source)
>> >>         at java.lang.reflect.Method.invoke(Unknown Source)
>> >>         at
>> >>
>> >> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
>> >>
>> >>         at
>> >>
>> >> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
>> >>
>> >>         at
>> >>
>> >> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
>> >>
>> >>         at
>> >>
>> >> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
>> >>
>> >>         at
>> >> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
>> >>         at java.lang.Thread.run(Unknown Source)
>> >>     Caused by: Sourced file: inline evaluation of: ``s=${FOO}; 
>> >> print(s);
>> >>     ;'' : Attempt to access property on undefined variable or class 
>> >> name
>> >>     : at Line: 1 : in file: inline evaluation of: ``s=${FOO}; 
>> >> print(s);
>> >>     ;'' : {
>> >
>> >
>> > ditto
>> >
>> >> And finally, I tried:
>> >>
>> >>     print("${FOO}");
>> >>
>> >> Which printed:
>> >>
>> >>     ${FOO}
>> >
>> >
>> > ditto
>> >
>> >> I still don't see how to do this ....
>> >>
>> >
>> > The above is correct, but the variable is not defined.
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
> 


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


Re: Accessing regex variables in Beanshell

Posted by sebb <se...@gmail.com>.
On 25/09/06, Philip Peake <ph...@vogon.net> wrote:
> Hmm... the variable is not defined ....
> But going back to my original e-mail, I said:
>
> >     I have an HTTP Request sampler. Contained in the body of the page
> >     returned by this is the word "Squirrel".
> >     As a child of the HTTP Request I have a Regular Expression
> >     Extractor (Post Processor) set up as follows:
> >
> >     Response Field:   <Body checked>
> >     Reference Name:   FOO
> >     Regular Expression:   (Squirrel)
> >     Template:   $1

As mentioned in another e-mail, this should be $1$

> >     Default Value:   "Missed"
> >
> >     If I understand the documentation correctly, this should
> >     initialize a variable called FOO, accessible as ${FOO} which will
> >     contain "Squirrel" if that is present in the body of the response
> >     processed by the HTTP Request sampler, or "Missed" as a value if
> >     it is not.
>
> To which you replied:
>
> >     > If I understand the documentation correctly, this should
> >     initialize a
> >     > variable called FOO, accessible as ${FOO} which will contain
> >     "Squirrel"
> >     > if that is present in the body of the response processed by the
> >     HTTP
> >     > Request sampler, or "Missed" as a value if it is not.
> >
> >     Yes.
>
> So, which is it?

The variable FOO will be set to the value of the template if the RE
matches, otherwise the variable FOO will be set to "Missed".

In your case, the value of the template was "$1", not "Squirrel", but
the rules still apply.

> Is it that variables defined in an imediately preceeding pos-processor
> is not available in the next?

The variables are available as soon as they have been defined, i.e. as
soon as the post-processor has been run.

> I am really trying to understand this....
>
> Philip
>
> -----------------------------------------------
>
>
>
> sebb wrote:
>
> > On 24/09/06, Philip Peake <ph...@vogon.net> wrote:
> >
> >> Thanks for pointing out that the ${VAR} variables are pre-processed.
> >> So I tried this:
> >>
> >>     s=vars.get("FOO");
> >>     print(s);
> >>
> >> It print out:
> >>
> >>     null
> >
> >
> > i.e. FOO is not defined as a variable
> >
> >> I also tried:
> >>
> >>     s=${FOO};
> >>     print(s);
> >>
> >> Which gave:
> >>
> >>     2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error
> >>     invoking bsh method eval
> >>      java.lang.reflect.InvocationTargetException
> >>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> >>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> >> Source)
> >>         at java.lang.reflect.Method.invoke(Unknown Source)
> >>         at
> >>
> >> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
> >>
> >>         at
> >>
> >> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
> >>
> >>         at
> >>
> >> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
> >>
> >>         at
> >>
> >> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
> >>
> >>         at
> >> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
> >>         at java.lang.Thread.run(Unknown Source)
> >>     Caused by: Sourced file: inline evaluation of: ``s=${FOO}; print(s);
> >>     ;'' : Attempt to access property on undefined variable or class name
> >>     : at Line: 1 : in file: inline evaluation of: ``s=${FOO}; print(s);
> >>     ;'' : {
> >
> >
> > ditto
> >
> >> And finally, I tried:
> >>
> >>     print("${FOO}");
> >>
> >> Which printed:
> >>
> >>     ${FOO}
> >
> >
> > ditto
> >
> >> I still don't see how to do this ....
> >>
> >
> > The above is correct, but the variable is not defined.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
>
>

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


Re: Accessing regex variables in Beanshell

Posted by Philip Peake <ph...@vogon.net>.
Hmm... the variable is not defined ....
But going back to my original e-mail, I said:

>     I have an HTTP Request sampler. Contained in the body of the page
>     returned by this is the word "Squirrel".
>     As a child of the HTTP Request I have a Regular Expression
>     Extractor (Post Processor) set up as follows:
>
>     Response Field:   <Body checked>
>     Reference Name:   FOO
>     Regular Expression:   (Squirrel)
>     Template:   $1
>     Default Value:   "Missed"
>
>     If I understand the documentation correctly, this should
>     initialize a variable called FOO, accessible as ${FOO} which will
>     contain "Squirrel" if that is present in the body of the response
>     processed by the HTTP Request sampler, or "Missed" as a value if
>     it is not. 

To which you replied:

>     > If I understand the documentation correctly, this should
>     initialize a
>     > variable called FOO, accessible as ${FOO} which will contain
>     "Squirrel"
>     > if that is present in the body of the response processed by the
>     HTTP
>     > Request sampler, or "Missed" as a value if it is not.
>
>     Yes.

So, which is it?
Is it that variables defined in an imediately preceeding pos-processor 
is not available in the next?

I am really trying to understand this....

Philip

-----------------------------------------------



sebb wrote:

> On 24/09/06, Philip Peake <ph...@vogon.net> wrote:
>
>> Thanks for pointing out that the ${VAR} variables are pre-processed.
>> So I tried this:
>>
>>     s=vars.get("FOO");
>>     print(s);
>>
>> It print out:
>>
>>     null
>
>
> i.e. FOO is not defined as a variable
>
>> I also tried:
>>
>>     s=${FOO};
>>     print(s);
>>
>> Which gave:
>>
>>     2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error
>>     invoking bsh method eval
>>      java.lang.reflect.InvocationTargetException
>>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown 
>> Source)
>>         at java.lang.reflect.Method.invoke(Unknown Source)
>>         at
>>     
>> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150) 
>>
>>         at
>>     
>> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186) 
>>
>>         at
>>     
>> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80) 
>>
>>         at
>>     
>> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428) 
>>
>>         at 
>> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
>>         at java.lang.Thread.run(Unknown Source)
>>     Caused by: Sourced file: inline evaluation of: ``s=${FOO}; print(s);
>>     ;'' : Attempt to access property on undefined variable or class name
>>     : at Line: 1 : in file: inline evaluation of: ``s=${FOO}; print(s);
>>     ;'' : {
>
>
> ditto
>
>> And finally, I tried:
>>
>>     print("${FOO}");
>>
>> Which printed:
>>
>>     ${FOO}
>
>
> ditto
>
>> I still don't see how to do this ....
>>
>
> The above is correct, but the variable is not defined.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org



Re: Accessing regex variables in Beanshell

Posted by sebb <se...@gmail.com>.
On 24/09/06, Philip Peake <ph...@vogon.net> wrote:
> Thanks for pointing out that the ${VAR} variables are pre-processed.
> So I tried this:
>
>     s=vars.get("FOO");
>     print(s);
>
> It print out:
>
>     null

i.e. FOO is not defined as a variable

> I also tried:
>
>     s=${FOO};
>     print(s);
>
> Which gave:
>
>     2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error
>     invoking bsh method eval
>      java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at
>     org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
>         at
>     org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
>         at
>     org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
>         at
>     org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
>         at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
>         at java.lang.Thread.run(Unknown Source)
>     Caused by: Sourced file: inline evaluation of: ``s=${FOO}; print(s);
>     ;'' : Attempt to access property on undefined variable or class name
>     : at Line: 1 : in file: inline evaluation of: ``s=${FOO}; print(s);
>     ;'' : {

ditto

> And finally, I tried:
>
>     print("${FOO}");
>
> Which printed:
>
>     ${FOO}

ditto

> I still don't see how to do this ....
>

The above is correct, but the variable is not defined.

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


Re: Accessing regex variables in Beanshell

Posted by Philip Peake <ph...@vogon.net>.
Thanks for pointing out that the ${VAR} variables are pre-processed.
So I tried this:

    s=vars.get("FOO");
    print(s);

It print out:

    null

I also tried:

    s=${FOO};
    print(s);

Which gave:

    2006/09/24 13:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error
    invoking bsh method eval
     java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at
    org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
        at
    org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
        at
    org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
        at
    org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
        at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
        at java.lang.Thread.run(Unknown Source)
    Caused by: Sourced file: inline evaluation of: ``s=${FOO}; print(s);
    ;'' : Attempt to access property on undefined variable or class name
    : at Line: 1 : in file: inline evaluation of: ``s=${FOO}; print(s);
    ;'' : {

And finally, I tried:

    print("${FOO}");

Which printed:

    ${FOO}

I still don't see how to do this ....

Philip

----------------------------------------





sebb wrote:
> On 23/09/06, Philip Peake <ph...@vogon.net> wrote:
>> Jmeter 2.2
>>
>> I am having problems picking up variables set by the Regular Expression
>> Extractor in a Beanshell.
>>
>> I have an HTTP Request sampler. Contained in the body of the page
>> returned by this is the word "Squirrel".
>> As a child of the HTTP Request I have a Regular Expression Extractor
>> (Post Processor) set up as follows:
>>
>> Response Field:   <Body checked>
>> Reference Name:   FOO
>> Regular Expression:   (Squirrel)
>> Template:   $1
>> Default Value:   "Missed"
>>
>> If I understand the documentation correctly, this should initialize a
>> variable called FOO, accessible as ${FOO} which will contain "Squirrel"
>> if that is present in the body of the response processed by the HTTP
>> Request sampler, or "Missed" as a value if it is not.
>
> Yes.
>
>> Following the Regex, again as a child of the same HTTP Request sampler,
>> I have a BeanShell PostProcessor.
>> This is where I am having difficulty. I cannot find a way to access the
>> ${FOO} variable.
>>
>> If I try:
>>
>>     print(${FOO});
>
> This will be replaced with
>
>   print(Squirrel);
>
> when you probably wanted
>
>  print("Squirrel");
>
>> I get this:
>>
>> 2006/09/22 17:58:59 ERROR - jmeter.util.BeanShellInterpreter: Error
>> invoking bsh method eval
>>  java.lang.reflect.InvocationTargetException
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>     at java.lang.reflect.Method.invoke(Unknown Source)
>>     at
>> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150) 
>>
>>     at
>> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186) 
>>
>>     at
>> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80) 
>>
>>     at
>> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428) 
>>
>>     at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
>>     at java.lang.Thread.run(Unknown Source)
>> Caused by: Sourced file: inline evaluation of: ``print(${FOO});'' :
>> Attempt to access property on undefined variable or class name : at
>> Line: 1 : in file: inline evaluation of: ``print(${FOO});'' : {
>>
>>     at bsh.BSHPrimarySuffix.doProperty(Unknown Source)
>>     at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
>>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>>     at bsh.BSHArguments.getArguments(Unknown Source)
>>     at bsh.BSHMethodInvocation.eval(Unknown Source)
>>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>>     at bsh.Interpreter.eval(Unknown Source)
>>     at bsh.Interpreter.eval(Unknown Source)
>>     at bsh.Interpreter.eval(Unknown Source)
>>     ... 10 more
>>
>> So, I tried this way:
>>
>> s=vars.get("${FOO}");
>> print(s);
>>
>> This prints out
>>
>>      null
>
> Yes, you are printing the value of the variable Squirrel.
>
>> So how exactly do I access the variable FOO set in the preceeding
>> (regex) post processor???
>>
>
> ${FOO}
>
> or
>
> vars.get("FOO");
>
> The former only works in the script pane of the BeanShell test
> element; variable substitution is not performed in files.
>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Accessing regex variables in Beanshell

Posted by sebb <se...@gmail.com>.
On 23/09/06, Philip Peake <ph...@vogon.net> wrote:
> Jmeter 2.2
>
> I am having problems picking up variables set by the Regular Expression
> Extractor in a Beanshell.
>
> I have an HTTP Request sampler. Contained in the body of the page
> returned by this is the word "Squirrel".
> As a child of the HTTP Request I have a Regular Expression Extractor
> (Post Processor) set up as follows:
>
> Response Field:   <Body checked>
> Reference Name:   FOO
> Regular Expression:   (Squirrel)
> Template:   $1
> Default Value:   "Missed"
>
> If I understand the documentation correctly, this should initialize a
> variable called FOO, accessible as ${FOO} which will contain "Squirrel"
> if that is present in the body of the response processed by the HTTP
> Request sampler, or "Missed" as a value if it is not.

Yes.

> Following the Regex, again as a child of the same HTTP Request sampler,
> I have a BeanShell PostProcessor.
> This is where I am having difficulty. I cannot find a way to access the
> ${FOO} variable.
>
> If I try:
>
>     print(${FOO});

This will be replaced with

   print(Squirrel);

when you probably wanted

  print("Squirrel");

> I get this:
>
> 2006/09/22 17:58:59 ERROR - jmeter.util.BeanShellInterpreter: Error
> invoking bsh method eval
>  java.lang.reflect.InvocationTargetException
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>     at java.lang.reflect.Method.invoke(Unknown Source)
>     at
> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:150)
>     at
> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
>     at
> org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:80)
>     at
> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:428)
>     at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
>     at java.lang.Thread.run(Unknown Source)
> Caused by: Sourced file: inline evaluation of: ``print(${FOO});'' :
> Attempt to access property on undefined variable or class name : at
> Line: 1 : in file: inline evaluation of: ``print(${FOO});'' : {
>
>     at bsh.BSHPrimarySuffix.doProperty(Unknown Source)
>     at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>     at bsh.BSHArguments.getArguments(Unknown Source)
>     at bsh.BSHMethodInvocation.eval(Unknown Source)
>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>     at bsh.BSHPrimaryExpression.eval(Unknown Source)
>     at bsh.Interpreter.eval(Unknown Source)
>     at bsh.Interpreter.eval(Unknown Source)
>     at bsh.Interpreter.eval(Unknown Source)
>     ... 10 more
>
> So, I tried this way:
>
> s=vars.get("${FOO}");
> print(s);
>
> This prints out
>
>      null

Yes, you are printing the value of the variable Squirrel.

> So how exactly do I access the variable FOO set in the preceeding
> (regex) post processor???
>

${FOO}

or

vars.get("FOO");

The former only works in the script pane of the BeanShell test
element; variable substitution is not performed in files.

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

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