JSR223 PreProcessor - Issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

JSR223 PreProcessor - Issue

UserJMeter999
Added JSR223 PreProcessor with Script Language = Beanshell (Beanshell
2.0lb5)


Code is below
**********************************************************************

String MESSAGE = vars.get("MESSAGE");
log.info("OLD ----- " + MESSAGE);

int my_counter = Integer.parseInt(vars.get("my_counter"));
log.info("Initial Counter ----- " + my_counter);
my_counter = my_counter + 1;
log.info("Incremented Counter ----- " + my_counter);

//vars.put("my_counter", String.valueOf(my_counter));
*vars.put("my_counter", my_counter);*
//vars.put("my_counter", ${my_counter});

String NEWMESSAGE ="";
NEWMESSAGE = MESSAGE.replace("MYBILLERACCOUNT", my_counter);
// NEWMESSAGE = MESSAGE.replace("MYBILLERACCOUNT", ${my_counter});
log.info("NEW ----" + NEWMESSAGE);


**********************************************************************
I tried few options of all the commented code above
***********************************************************************
Getting below error line highlighted in bold

2018-06-28 14:07:37,683 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223
script, JSR223 PreProcessor - {"account": {"accountType":
"INDIV","billerAccountId": "MYBILLERACCOUNT: []}
javax.script.ScriptException: Sourced file: inline evaluation of: ``String
MESSAGE = vars.get("MESSAGE"); log.info("OLD ----- " + MESSAGE);  int my_ .
. . '' : Error in method invocation: Method put( java.lang.String, int )
not found in class'org.apache.jmeter.threads.JMeterVariables' : at Line: 10
: in file: inline evaluation of: ``String MESSAGE = vars.get("MESSAGE");
log.info("OLD ----- " + MESSAGE);  int my_ . . . '' : vars .put (
"my_counter" , my_counter )
 in inline evaluation of: ``String MESSAGE = vars.get("MESSAGE"); log.info("OLD
----- " + MESSAGE);  int my_ . . . '' at line number 10
Reply | Threaded
Open this post in threaded view
|

Re: JSR223 PreProcessor - Issue

support@ubikloadpack.com
Hello,
1/ *vars.put("my_counter", my_counter);*
Should be:
*vars.put("my_counter", Integer.toString(my_counter));*


2/ Switch to Groovy instead of Beanshell and check cache . Beanshell does
not perform well


UbikLoadPack Support Team
@ubikloadpack


On Thu, Jun 28, 2018 at 9:13 PM, JMeter User <[hidden email]> wrote:

> Added JSR223 PreProcessor with Script Language = Beanshell (Beanshell
> 2.0lb5)
>
>
> Code is below
> **********************************************************************
>
> String MESSAGE = vars.get("MESSAGE");
> log.info("OLD ----- " + MESSAGE);
>
> int my_counter = Integer.parseInt(vars.get("my_counter"));
> log.info("Initial Counter ----- " + my_counter);
> my_counter = my_counter + 1;
> log.info("Incremented Counter ----- " + my_counter);
>
> //vars.put("my_counter", String.valueOf(my_counter));
> *vars.put("my_counter", my_counter);*
> //vars.put("my_counter", ${my_counter});
>
> String NEWMESSAGE ="";
> NEWMESSAGE = MESSAGE.replace("MYBILLERACCOUNT", my_counter);
> // NEWMESSAGE = MESSAGE.replace("MYBILLERACCOUNT", ${my_counter});
> log.info("NEW ----" + NEWMESSAGE);
>
>
> **********************************************************************
> I tried few options of all the commented code above
> ***********************************************************************
> Getting below error line highlighted in bold
>
> 2018-06-28 14:07:37,683 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223
> script, JSR223 PreProcessor - {"account": {"accountType":
> "INDIV","billerAccountId": "MYBILLERACCOUNT: []}
> javax.script.ScriptException: Sourced file: inline evaluation of: ``String
> MESSAGE = vars.get("MESSAGE"); log.info("OLD ----- " + MESSAGE);  int my_
> .
> . . '' : Error in method invocation: Method put( java.lang.String, int )
> not found in class'org.apache.jmeter.threads.JMeterVariables' : at Line:
> 10
> : in file: inline evaluation of: ``String MESSAGE = vars.get("MESSAGE");
> log.info("OLD ----- " + MESSAGE);  int my_ . . . '' : vars .put (
> "my_counter" , my_counter )
>  in inline evaluation of: ``String MESSAGE = vars.get("MESSAGE"); log.info
> ("OLD
> ----- " + MESSAGE);  int my_ . . . '' at line number 10
>
Reply | Threaded
Open this post in threaded view
|

Re: JSR223 PreProcessor - Issue

UserJMeter999
This post was updated on .
When i try to use this function in JSR Preprocessor
${__FileToString(C:\Users\xyz\Desktop\Test.txt,,MESSAGE)}

getting below error
2018-06-28 14:38:19,325 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223
script, JSR223 PreProcessor -
in inline evaluation of: ``{"account": {"accountType": "INDIV"," . . . '' at
line number 1



But in if we see MESSAGE in post debug processor i see value is being assigned to MESSAGE variable as expected.

--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org

Reply | Threaded
Open this post in threaded view
|

Re: JSR223 PreProcessor - Issue

glinius@live.com
Don't inline  JMeter Functions and/or Variables
<https://jmeter.apache.org/usermanual/functions.html>   into Groovy code.

As per  JSR223 Sampler documentation
<http://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler>  


> When using this feature, ensure your script code does not use JMeter
> variables directly in script code as caching would only cache first
> replacement. Instead use script parameters

 

If you're looking for a "pure"  Groovy
<https://www.blazemeter.com/blog/groovy-new-black>   equivalent of your code
it would be something like:


> vars.put('MESSAGE', new File('C:\\Users\\xyz\\Desktop\\Test.txt').text)





--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html

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