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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to