Summary of BeanShell usage in JMeter (i.)

Source: Internet
Author: User

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.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.