Software testing skills, JMeter stress testing tutorial (2)

Table of contents

foreword

1. Case scenario

2. Login request

3. Json extractor

4. Association request

Five, the pit encountered


foreword

Now the login of many interfaces returns a json data, the token value is in the returned json, and the value in the json can also be directly extracted in jmeter. The
token returned by the previous interface is used as the input parameter of the next interface

1. Case scenario

I now have a login interface A, which returns a token value after successful login. There is an interface B for obtaining the bound card number, but interface B must be logged in first and then passed the login token to access

A interface login interface document basic information
Access address: http://127.0.0.1:8000/api/v1/login/ Request
type: POST
request header: application/json
Request parameters: {"username":"test", " password”:”123456”}

The request and returned message information of interface A are as follows
 

D:\>http http://127.0.0.1:8000/api/v1/login/ username=test password=123456 -v
POST /api/v1/login/ HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 42
Content-Type: application/json
Host: 127.0.0.1:8000
User-Agent: HTTPie/1.0.3
{
    "password": "123456",
    "username": "test"
}
HTTP/1.1 200 OK
Allow: POST, OPTIONS
Content-Length: 109
Content-Type: application/json
Date: Sat, 21 Sep 2019 15:37:06 GMT
Server: WSGIServer/0.2 CPython/3.6.0
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
{
    "code": 0,
    "msg": "login success!",
    "token": "234af73571da46ade79ea6a74961b1d23d609b79",
    "username": "test"
}

Interface B obtains the basic information of the interface document for binding the card number

Access address: http://127.0.0.1:8000/api/v1/user/info/
Request type: GET
Request header: Content-Type: application/json
Request header token parameter: Authorization: Token xxxxx login token xxxxx

2. Login request

First add the http request in jmeter and fill in the parameters of the login interface

The HTTP information header manager adds the post request type: Content-Type: application/json
After running, check the number of results, and you can see that the token value we want is returned correctly

3. Json extractor

Add Post Processor - Json Extractor

Extract the token value from the returned result Returned result

{
    "code": 0,
    "msg": "login success!",
    "token": "234af73571da46ade79ea6a74961b1d23d609b79",
    "username": "test"
}

JSON extractor parameter description:
Names of created variables: parameter name
JSON Path expressions: extraction expression
Match No. (0 for Random): match rule, -1 all, 0 random, 1 first
Compute concatenation va: if there is a match To multiple values, select this option, all values ​​will be saved to _ALL, and use commas to separate each value, note that Match No. (0 for Random) needs to be -1 to be valid, otherwise only one value can be matched
Default Values: Give the default value if it is not extracted

4. Association request

The next request header needs to use the above token value

Add a header manager, refer to the token parameter ${token}
to view the result, and request the associated parameters of the header
to view the response result successfully and return it correctly

Five, the pit encountered

When linking parameters, I encountered a pitfall. The requested parameters were all correct, but an error was reported:
Response code: Non HTTP response code: org.apache.http.NoHttpResponseException

After checking the information, it is necessary to implement the client of the first request in JAVA, so that the normal association can be successful.


              [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

2. Interface automation project actual combat

3. Actual Combat of Web Automation Project


4. Actual Combat of App Automation Project

5. Resume of first-tier manufacturers


6. Test and develop DevOps system

7. Commonly used automated testing tools


Eight, JMeter performance test

9. Summary (little surprise at the end)

life is long so add oil. Every effort will not be let down, as long as you persevere, there will be rewards in the end. Cherish your time and pursue your dreams. Don't forget the original intention, forge ahead. Your future is in your hands!

Life is short, time is precious, we cannot predict what will happen in the future, but we can grasp the present moment. Cherish every day and work hard to make yourself stronger and better. Firm belief, persistent pursuit, success will eventually belong to you!

Only by constantly challenging yourself can you constantly surpass yourself. Persist in pursuing your dreams and move forward bravely, and you will find that the process of struggle is so beautiful and worthwhile. Believe in yourself, you can do it!

Information acquisition method:
This document and video information should be the most comprehensive and complete preparation warehouse for friends who want to engage in [software testing]. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. Hope Can help you too! All of the above can be shared, click the small card below to enter the group to receive.

Guess you like

Origin blog.csdn.net/NHB456789/article/details/131306945