BeanShell PreProcessor updates User define variables

时间秒杀一切 提交于 2019-12-25 16:58:08

问题


I'm very new at JMeter issues.

In a test script i have a BeanShell PreProcessor element that updates some variables previously defined at a "User Defined Variables" element.

Latter those variables are used in "Http Requests". However, the value that is used in the http request is the default one.

The scripts seems to be working due to some debug print();

My question is if it's necessary to delay the script to be sure that the BeanShell finishes?

Thanks a lot for your attention


回答1:


There is no need to put any delay to Beanshell Pre-Processor as it's being executed before request. I'd recommend to check your jmeter.log file to see if there are any scripting issues as Beanshell Pre-Processor does not report errors anywhere including View Results Tree listener.

There are at least 2 ways to assure that everything is fine with your Beanshell script:

  1. Put your debug print code after variables replace logic to see if it fires
  2. Use JMeter __Beahshell function right in your HTTP request. If it's ok - View Results Tree will demonstrate beanshell-generated value. If not - the field will be blank and relevant error will be displayed in the log.

Example test case:

Given following Test Plan structure:

  • Thread Group with 1 user and 1 loop
  • HTTP GET Request to google.com with path of / and parameter q

If you provide as parameter "q" following beanshell function:

${__BeanShell(System.currentTimeMillis())}

and look into View Results Tree "Request" tab you should see something like:

GET http://www.google.com/?q=1385206045832

and if you change function to something incorrect like:

${__BeanShell(Something.incorrect())}

you'll see a blank request.

The correct way of changing existing variable (or creating new if variable doesn't exist) looks like

vars.put("variablename", "variablevalue");

*Important: * JMeter Variables are Java Strings, if you're trying to set something else (date, integer, whatever) to JMeter Variable you need to cast it to String somehow.

Example:

int i = 5;
vars.put("int_i", String.valueOf(i));

Hope this helps.




回答2:


You can update the vale of a "user defined variable".

  1. You have to create a bean shell sampler
  2. vars.put("user_defined_variable", "newvalue");

@theINtoy got it right.

http://www.blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell




回答3:


I'm new to jmeter too but as I know variables defined in "User defined variables" are constants, so you can't change them. I recommend to use "User Parameters" in preprocessors or CSV Data Set Config.



来源:https://stackoverflow.com/questions/20150366/beanshell-preprocessor-updates-user-define-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!