JMeter custom Sampler

1. Background

I believe everyone in the use JMeter test tools, often encounter a situation comes sampler can not meet the test requirements. Faced with this situation, the usual approach is to use testing purposes universal custom Java Request of. This method has drawbacks, as long as the underlying logic code is altered, it is necessary to re-package, but also in order to restart new JMeter bytecode is loaded into the JVM. A lot of trouble, if the interface a lot, it makes you tired to vomit blood and the code for weak people who feel like hieroglyphics, a wood there.

2. The purpose

For the above, there is a custom-developed idea of ​​Sampler. We must clear two things:

  1. Such a request you want to send, JMeter sampler comes you can not meet the test.
  2. This transaction initiated by the way, in your future testing process often use.

Based on the above two points, I think we can customize a sampler, and vice versa little significance. (Weak development of skills can be developed under the "bribe" students, help write plug-ins. Hello, everyone is really good!)

3. Ideas

  • A custom development Sampler general idea is as follows:

image

  • Teach you a simple idea, directly to the JMeter source package decompile, find sample source code, a simple look, I know how to write.

4. combat

How to build a plug-in development environment, I will not go into details, everyone on their own Baidu, such as those required jar package, you can use Maven form, you can own the specified package copy to your project, build.

  • Write two classes

image

We look xxxSamplerGui class some of the highlights:

image

Main methods:

image

Direct return sampler's name, the GUI page to see the name of the sampler is defined here.

image

This method creates a new Sampler, and then set the data interface to the new instance Sampler.

image

Used to interface data to the Sampler, before calling their implementation, please call at super.configureTestElement (element), this will help move some default data.

image

In the new interface, reset the time to call for some of the default GUI interface controls need to reset the display value.

We look at xxxSampler class some of the highlights:

image

Main methods:

image

image

Generally is to write the above, the writing is not especially detailed than, in fact, the main idea is to write, hoping to help you (the only quick way is to look at their own JMeter underlying source code, the source code to read, write these write these code easy).

Guess you like

Origin www.cnblogs.com/leebaul/p/11305555.html