Previous JMeter Bean shell Use (a) a brief introduction of the bean shell in the next jmeter, this article is a supplement to the above, mainly summarizes the common scenarios and methods, I believe these basic can cover most of the needs. This section reads as follows:
First, the operation variable
Second, Operation Properties
Iii. Custom Functions
Iv. referencing external java files
V. Referencing an external class file
Vi. referencing external jar packages
Vii. other uses (accept parameters, log, etc.)
One, the action variable: the variable can be accessed by using the bean shell built-in object VARs
A) vars.get ("name"): Gets the value of the variable from the JMeter
b) vars.put ("Key", "value"): Data stored in the JMeter variable
Operation Properties: property can be accessed by using the bean shell built-in object props
A) Props.get ("START. HMS "); Note: Start.hms is a property name, defined in file jmeter.properties
b) Props.put ("PROP1", "1234");
Third, Custom functions:
In BeanShell, we can use the Java language Custom function to handle the specific logic, combining the BeanShell built-in objects for variable access, so that we test to improve the flexibility of the script.
Example:
1. Add a variable to the test plan: Hello = Kitty
2, Debug sampler-1 and debug Sampler-2 Nothing to deal with, used to query comparison Beahshell processing results before and after
3. The script in BeanShell Sampler is as follows:
4. Operation Result:
- Debug sampler-1 Display: Hello=kitty
- The result returned in BeanShell Sampler is: Success
- Debug sampler-1 Display: hello=world,jmeter=111111
Iv. Referencing external java files:
Is there any way to think that the custom function in the above (c) is too cumbersome and not beautiful? And if we already have a ready-made Java source file or class file, is there any way we can reference it directly in Jemter? This is what this section is going to cover, directly on the example:
1, if I have a Java source file, named: Myclass.java, the code is as follows:
Package Test;public class myclass{public int Add (int a, int b) { return a + b; } }
JMeter Bean Shell Use (ii)