JMeter Bean Shell Use (ii)

Source: Internet
Author: User
Tags vars

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)

Related Article

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.