jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: Accessing regex variables in Beanshell
Date Mon, 25 Sep 2006 12:31:33 GMT
On 25/09/06, Philip Peake <philip@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 <philip@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


Mime
View raw message