Jmeter solve cross-thread group takes parameter values problem! (Did not try)

Source https://mp.weixin.qq.com/s/q7ArxwnX1sOfa9tfHouSBQ

If the work you are already doing Interface testing jmeter, or performance testing, you may encounter a trouble.

 

That is jmeter variable values ​​can not cross-thread group transfer.

 

 

 

 

Look, the official explanation has been given.

 

This is not jmeter flaws, this is by design of jmeter.

 

If the variable before starting the test has been determined, we can use parametric association can be achieved.

 

But if the value is dynamically generated each time through the loop, the value will change once, how to get it?

 

At this point, you might go to Baidu, did not you?

 

You will find that very strange, all chance of Baidu results are always told you a thousand times *** use Beanshell, write some unintelligible code.

 

If you do not know java, you see that it began to write the code, but also says some of the obscure stuff, you are not already started a headache.

 

If so, then you continue to look down, I'll teach you hands.

 

Both methods, easy to get, you do not have to write some code which consequently do not understand.

 

1 define attributes Method

 

Ideas: jmeter, the attribute is global, can be set dynamically; and independent variables belonging to each thread

 

The first step: we jmeter, add two thread groups

 

Step Two: In the first thread group, calling an interface, you want to extract the stored value to a variable

 

Third step: in the first thread group, Beanshell add a post-processor.

 

Then open the menu bar Tools -> Function Assistant dialog box (Function Helper Dialog)

 

In pop, select __BeanShell function, the attribute name (English) expression first value input to be stored, the second value of the input variable name in the second step you define, generating function.

 

Postprocessor after copying function, pop off, to paste BeanShell Script window function.

 

 

 

 

Fourth step: in the second thread group, adding a 'user parameters', add variable (Add variable).

 

Setting the variable name, function assistant opened again, __P selected function, the first function value the value of the text input box Step $ {name} attribute set, generating function, copy function, pop off, to paste it into value added variable text box.

 

 

 

 

Fifth step: in the second thread group, using a defined interface parameters variable} $ {variable name

 

Thus, to achieve a cross-thread passing parameters between groups.

 

Is not it simple. It's so easy!

 

Note: If you want to set a plurality of attributes, in the third step, when a plurality of pasting functions, attributes modify the function names and variable names, function between each English ';' apart.


If you feel difficult, do not lose heart, continue to look down, I will teach you a method easier to understand.

 

2 file transfer method

 

Ideas: a thread group run results to a file, another thread group, by reading the file csv, and then extract the desired values ​​in the file as input variables

 

Step 1: jmeter, add two thread groups

 

Step Two: In the first thread group, call interface, then add the Monitor -> Save to file a response, set up to save the file path and file name prefix

 

 

 

 

Third step: In the second thread group, adding a csv file setting data (csv set data config).

 

File name is set to the second step, provided save file path; variable name itself is defined; delimiter is set to '\ t'

 

(Why this place use \ t, leave a job, everyone thinking about it)

 

 

 

 

Step 4: Add the regular expression extractor (extractor or json), apply to select 'Jmeter variable Name to use', and then enter the variable name is read csv file settings; re-writing regular extraction of formula

 

 

 

 

Step Five: In the second thread group, add an interface, use the variable name is being extracted in the

 

At this point, the file transfer process is completed.

 

Both methods are not quite simple, not to write obfuscated code! And we have achieved a cross-thread group of mass participation values.


Of course, these two methods can achieve cross-thread group to pass parameters values, but they still have differences.

 

If you want to learn more about the differences between the two methods is that they can focus on lemon class public number, or search for lemons class institutions in Tencent classroom, Follow us for more practical and useful test of skills sharing.

 

Guess you like

Origin www.cnblogs.com/kaibindirver/p/11723466.html