The most detailed in the whole network, Jmeter performance test - detailed performance basics, interface association and writing Java script (3)


foreword

interface association

Interface association is to extract the dynamic data information of the front interface and use it as the incoming parameter of the back interface.
But please note that if you use cookies to manage information, use the cookie manager, not the extractor!

And do not modify any content of the cookie manager information without knowing the content of the cookie.
To be conservative, it is recommended that as long as the login interface is used, it is best to add cookies, regardless of whether cookies are actually used.

JSON extractor

In the view result tree, you can change the format of the response content

Please add a picture description

After selecting the json format here, the response content will be displayed in json format

Please add a picture description

There is an input box below this, in which you can enter the extraction formula of json, here you can test the extraction formula of json

Please add a picture description

So back to the topic, to extract these data and use them in the script, you need to use the Json extractor.
Right click on the thread group, add post processor -> json extractor

Please add a picture description

The method of use is as shown in the figure above. It is very simple. Enter the variable name in Names of created variables. This variable name is used on the script. Then fill in the JSON extraction formula in JSON Path expressions.

In addition, if JSON proposes multiple values, it will return a list. At this time, if Match No is filled or not filled, different results will be produced.

When it is not filled or is 0, a value is randomly selected from the list;
when it is -1, each value in the list will be output, starting from 1, such as goods_1, goods_2, goods_3...

Please add a picture description

When it is 0, it takes the value of the corresponding subscript (the subscript starts from 1)

Please add a picture description

Finally, if you want to fill in multiple extraction formulas in a JSON extractor, you must fill in default Values, and use ";" to distinguish between each variable and the extraction formula.

Please add a picture description

Please add a picture description

regular extractor

The regular expression test can be tested here: https://c.runoob.com/front-end/854
There is a universal regular expression: left border (.*?) right border, but this expression cannot match newline characters .

Please add a picture description

If you want to extract multiple values, you can refer to the following method:

Regular expression: "gqid": "(. ?)"(. ?) "token": "(. ?)"
There are 3 regular expressions (. ?) here, which
means that 3 values ​​will be extracted when extracting, But what is actually needed is actually only gqid and token, two values, so a template is needed.

Template: 1 11 3 3 3
Since there are 3 regular expressions (.?), write 1 1 here in the template1 3 3 3 means to extract the value of the 1st and 3rd (.?)

Please add a picture description

If the extraction result is to be used, it is not simply to use re1, but to use re1_g1 and re1_g2

Please add a picture description

Write java script in Jmeter

Beansehll

First of all, Beanshell is a small, free, embeddable java source interpreter. It can execute java syntax and expressions

In Jmeter, Beanshell can do:
introduce its own jar package to realize enhanced functions;
write java code to realize its own logic functions;
pass values ​​across thread groups;

During performance testing, please do not use any original Beanshell, because its performance is not good. If some additional scripting is required, it is recommended to use JSR223 instead of Beanshell.

JSR223

The use of JSR223 is the same as that of Beanshell, so I won’t introduce more, just briefly introduce some examples. In
addition, both JSR223 and Beanshell can directly refer to variables on jmeter, and the reference method is also ${}

Get verification code from Redis:

import redis.clients.jedis.Jedis;

Jedis jedis = new Jedis("redis地址", 6379); // redis默认端口是6379
jedis.auth("密码");
String key = String.format("redis上的key")   
String value = jedis.get(key);
vars.put("ver",value)
The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

There will always be wind and rain in life, but we can't back down. As long as we have hope in our hearts and work hard unremittingly, we will be able to surpass ourselves and create our own beautiful future!

Don't give up easily, because you never know what surprises tomorrow will bring you. Those who persist in their dreams will eventually succeed, it's just a matter of time. Cherish the time, seize the opportunity, and let yourself become a person who keeps improving!

As long as you have a dream in your heart, don't stop struggling. Difficulties are only temporary, but success is eternal. You may fall down on the road of life, but only by persisting in getting up can you go to glory.

Guess you like

Origin blog.csdn.net/shuang_waiwai/article/details/130086985