First, what is the bean Shell
- BeanShell is a scripting language that conforms fully to the Java syntax specification and has its own syntax and methods.
- BeanShell is a loosely typed scripting language (this is similar to JS);
- BeanShell is written in Java, a small, free, downloadable, embedded Java source code interpreter with object scripting language features and a very streamlined interpreter jar file size of 175k.
- BeanShell executes standard Java statements and expressions, plus some scripting commands and syntax.
Ii. What Bean Shell does JMeter have?
Timer: BeanShell Timer
Front Processor: BeanShell preprocessor
Sampler: BeanShell Sampler
Post Processor: BeanShell postprocessor
Assertion: BeanShell Assertion
Listener: BeanShell Listener
Third, the use of BeanShell
Using examples to explain the use of BeanShell
Usage Scenario: Mobile phone number registration, login, bind card business
There are two ways to randomly generate non-repeating phone numbers:
1. Register the interface parameters:
Merchant_id=00000001&bizcode=uums_user_register&mobile=13${__random (000000000,999999999,Phone)} &password=888888
In this way, a random number within a range is generated by JMeter, and then the login service is followed by a direct reference to 13${phone}.
Login interface:
merchant_id=00000001&bizcode=uums_login&login_type=104&login_account=13${Phone}& password=888888
Mode 2:
Implemented through BeanShell:
String time ="${__time (,)}";int[] arr = { -, the, -, -};intIndex= (int) (Math.random () *arr.length);//generates an integer value of 0-(ARR.LENGTH-1), which is also an index of the arrayintRand =Arr[index]; String Time=time.substring (6, -); Vars.put ("Phone", rand+""+${__random (0,9, RandNo1)}+""+time+""+${__random (0,9, RandNo2)});//if there are duplicates during testing, other random numbers can also be constructed//1476063656393//6063697317//063754461
Note: BeanShell the difference between placing the registered sampler below and placing it under the test case:
Executes BeanShell sampler once every time
Under Registration Sampler: Execute only once at a time:
Summary of BeanShell usage in JMeter (i.)