On 3 September 2013 11:03, Richard Gaywood <[email protected]> wrote:
> Further to the below, I've written the below script which I've run through
> the beanshell interpreter myself with java bsh.Interpreter test.bsh, and it
> works.
>
> Script:
>
> String foo = "foo";
>> String bar = "bar";
>> if (foo.contains("o")) {
>> System.out.println(foo);
>> }
>> if (bar.contains("o")) {
>> System.out.println(bar);
>> }
>>
>> int i=0;
>> String subject;
>> String guid;
>> do {
>> subject = "foo DESIREDTEXT"+Integer.toString(i);
>> guid =  "guid"+Integer.toString(i);
>> i++;
>> } while (! subject.contains("DESIREDTEXT3"));
>> System.out.println(guid);
>
>
>
> Output:
>
> foo
>> guid3
>
>
>
> So the BSH itself looks OK to me, can't figure out why JMeter doesn't like
> it...

Most likely cause is an unexpected quoting or variable replacement
issue so BSH does not get passed what you expect.

Try putting the script in a file.

And/or try the problematic statement on its own, and gradually build
up the rest of the script.
You can do that by selective commenting of lines with //

>
>
> On Tue, Sep 3, 2013 at 9:33 AM, Richard Gaywood 
> <[email protected]>wrote:
>
>> Hi list.
>>
>> I have a slightly complex test I'm working on where I process a JSON
>> response. I loop through looking at each value of one particular field,
>> where the nth value is some string I know I need. Then I want to choose the
>> nth value of a second field to reuse in the test.
>>
>> So I have two regex extractors set to match number -1, each grabbing one
>> of the two  fields, then this in a BSH post-processor:
>>
>>
>> int i=0;
>> String subject;
>> String guid;
>> do {
>> subject = vars.get("subjects_"+Integer.toString(i));
>> guid =  vars.get("pair_guids_"+Integer.toString(i));
>>  i++;
>> } while (i<5);
>> //} while (! subject.contains("DESIREDSTRING"));
>>
>> vars.put("subject", subject );
>> vars.put("guid", guid );
>>
>>
>> With the i<5 check (debugging code), it works fine, but obviously doesn't
>> always grab the correct element. But with the alternative while clause
>> using String.contains, I get the following error:
>>
>> 2013/09/03 09:30:17 ERROR - jmeter.util.BeanShellInterpreter: Error
>> invoking bsh method: eval Sourced file: inline evaluation of: `` int i=0;
>> String subject; String guid; do { subject = vars.get("subjects_"+Inte . .
>> . ''
>> 2013/09/03 09:30:17 WARN  - jmeter.extractor.BeanShellPostProcessor:
>> Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error
>> invoking bsh method: eval Sourced file: inline evaluation of: `` int i=0;
>> String subject; String guid; do { subject = vars.get("subjects_"+Inte . .
>> . ''
>>
>> I get similar errors on method calls like String.startsWith() too. Can
>> anyone shed any light on why?
>>
>> Thanks in advance,
>>
>> Richard
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to