On 14 May 2012 17:30, <[email protected]> wrote:
> I have a BeanShell Sampler that I have placed into a Once Only Controller.
>
> In it, I have some code to help randomize my test in ways that I can't
> easily do.
>
> The code is :
>
> <start code>
> import java.io.*;
> import java.util.*;
> int n = 0;
> for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
> \\job_titles.txt") ); sc.hasNext(); )
> {
> String line = sc.nextLine();
> line = line.replaceAll(" ", "+");
> vars.put("otl_JOB_TITLES_" + n, line);
> n++;
> }
>
> vars.put("otl_Counter", Integer.toString(n));
>
> </end code>
>
>
> However, as I am still developing this, I wanted to add a line to write the
> value of the counter variable to the logfile.
>
> When I add ${__logn(Counter is: ${otl_Counter})}; to the end of the file,
> after the final vars.put(), I get the following error:
>
>
> 2012/05/14 11:22:43 ERROR - jmeter.util.BeanShellInterpreter: Error
> invoking bsh method: eval Sourced file: inline evaluation of: ``import
> java.io.*; import java.util.*; int n = 0; for(Scanner sc = new Scanner
> ( n . . . '' Token Parsing Error: Lexical error at line 4, column 50.
> Encountered: "L" (76), after : "\"..\\tests\\"
Read the error message - it's complaining about "L" after "tests\\"
Looks like an escaping error.
Try using / instead of \\ in the path name.
> What am I doing wrong? Based on some Google searches and the jmeter docs, I
> would think that would work.
>
>
> For clarity, here is the full code that produces the error:
>
> <start code>
> import java.io.*;
> import java.util.*;
> int n = 0;
> for(Scanner sc = new Scanner( new File("..\\tests\\LoadTest\\resources
> \\job_titles.txt") ); sc.hasNext(); )
> {
> String line = sc.nextLine();
> line = line.replaceAll(" ", "+");
> vars.put("otl_JOB_TITLES_" + n, line);
> n++;
> }
>
> vars.put("otl_Counter", Integer.toString(n));
> ${__logn(Counter is: ${otl_Counter})};
> </end code>
>
>
>
> Thank you.
>
>
> Lee Lowder
>
> This communication and any attachments are confidential, protected by
> Communications Privacy Act 18 USCS § 2510, solely for the use of the intended
> recipient, and may contain legally privileged material. If you are not the
> intended recipient, please return or destroy it immediately. Thank you.
>
> ---------------------------------------------------------------------
> 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]