Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

BeanShell Sampler in JMeter

Shulou Source: shulou.com Published: 2022-06-03 04:59:27 09月23日 Update

BeanShell is a lightweight scripting language written in pure java.

BeanShell Sampler can be scripted in jmeter.

There are three common built-in variables:

log

Used to print logs in jmeter.log, you can print strings, variables

log.info("hello world");

vars

Used to access jmeter thread variables, usually used to access string content, but also to access objects

vars.get()

String mykey = vars.get("keyname"); ----Get the value of the thread variable name keyname and save it in mykey

String cookie11 = vars.get("COOKIE_JSESSIONID");

vars.put()

vars.put("keyname", "value"); ----Save value to jmeter thread variable keyname

vars.put("fcy", "tester");

Thread group--Add--Sampler--Debug Sampler, run, view Debug Sampler through the result tree, you can see all saved variables

Save it to a variable so that you can use it later: fcy = vars.get("fcy"), or fcy = "${fcy}"

Note: For fcy = "${fcy}", variables can be used in this way, but attributes cannot.

Properties can only be used with props.get(), the_P function, or the_property function.

3. props

Access jmeter attribute, key and value in parameters are in string form

ymd = props.get("START.YMD"); gets the value of attribute START.YMD (script start date)

props.put("PROP1", "1234");

Store 1234 in global attribute PROP1

Note: For attribute variables (global variables), generally restart jmeter to take effect, after using props, it is best to restart jmeter.

access attribute tom

Thread group--Add--Sampler--Debug Sampler, run, view Debug Sampler through the result tree, you can see all saved properties

4. Difference between thread variables and attributes:

Thread variables are local variables; attributes are global variables.

For attribute variables (global variables), generally restart jmeter to take effect, after using props, it is best to restart jmeter.

Tags: Variables properties threads global access characters strings scripts generally speaking functions best fruit trees runs people methods of use content parameters objects that is local Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Shulou Technology Linux vpn