Software testing skills, JMeter stress testing tutorial, regular expression extraction (3)

Table of contents

foreword

1. Scenarios

2. Login request

3. Regular extractor

4. Reference parameters

          


foreword

= interface association, the token returned by the previous interface is used as the input parameter of the next interface, in addition to the extraction with the json extractor mentioned in the previous article, it can also be extracted with regular expressions

The json extractor can only extract data in json format, and the regular pattern can match any return

1. Scenarios

I now have a login interface A, which returns a token value after successful login, and an interface B that obtains the bound card number, but interface B must log in first and then pass 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 the A interface 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 bound to 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. Regular extractor

Add Post Processor - Regular Extractor

The returned result, extract the value corresponding to the token from the result: 50c7e57363141459fab998376350ed3c3dee1baf
 

Regular extractor parameter description:

Response fields to check: sample data source, subject is selected by default

Reference name: the variable name (re_token) when referenced elsewhere, which can be customized

Reference method: ${reference name}

Regular expression: data extractor, the value you want to get in () brackets, such as: "token": "(.*?)"

Template: $$ corresponds to the regular expression extractor type. -1 for all, 0 for random, 1 for the first and 2 for the second, and so on, if there is only one regularity, generally fill in $1$

Matching numbers: All the results of the regular expression matching data can be regarded as an array, and the matching numbers can be regarded as the number of elements of the array - 1 means all, 0 is
random, 1 is the first, 2 is the second, and so on analogy. If only the first matching value is obtained, fill in 1

Default value: the default value when the matching fails, you can write whatever you want, or you can leave it blank, or use a null value when checking failure

4. Reference parameters

The next request refers to the token parameter above
to view the result, and the reference is successful
Please add a picture description


              [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/131307552