jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Gaywood <richardgayw...@gmail.com>
Subject Re: String.contains() causes syntax error in BeanShell post-processor
Date Tue, 03 Sep 2013 10:03:45 GMT
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...



On Tue, Sep 3, 2013 at 9:33 AM, Richard Gaywood <richardgaywood@gmail.com>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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message