3- jmeter pressure measured learning data extracting json inside the token associated parameters

Foreword

Now many login interface is to return a json data, token value in the json returned inside, you can extract the value in the json which directly jmeter inside.
Return token on an interface of the interface as the next reference.

Case scenario

I now have a landing interfaces A, returns a token value after a successful landing. There is a binding acquisition card interface B, but B must first login interface to transfer token to log in to access
the A interface login interface documentation basic information

A request interface and return the following message information

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"
}

B interface card interface to obtain binding document basic information

  • Access Address: http://127.0.0.1:8000/api/v1/user/info/
  • Request Type: GET
  • Request headers: Content-Type: application / json
  • Request header token argument: Authorization: Token xxxxx login token xxxxx

Login request

First add http request jmeter inside, fill in login interface parameters

HTTP header added post request manager Type: Content-Type: application / json

After running to see the number of results, you can see the correct return token values ​​we want

Json extractor

Add extractor postprocessor -Json

Token values ​​extracted from the returned results

Return result

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

JSON extractor parameters:

  • Names of created variables parameter name
  • JSON Path expressions extraction expression
  • Match No.(0 for Random) 匹配规则,-1所有,0随机,1第一个
  • Compute concatenation va 如果有匹配到多个值,选择此项,会将全部值保存到_ALL,并使用逗号分割每个值,注意Match No. (0 for Random)需要为-1才有效,不然只能匹配到一个值了
  • Default Values 没提取到就给默认值

关联请求

下个请求头部需要用到上面的token值

添加头部管理器,引用token参数 ${token}

查看结果,请求头部关联参数成功

查看响应结果也能正确的返回

遇到的坑

参数关联的时候,遇到一个坑,请求的参数都对,但是报错:
Response code: Non HTTP response code: org.apache.http.NoHttpResponseException

后来查资料,需要把第一个请求的的客户端实现用JAVA方式实现,才能正常的关联成功

Guess you like

Origin www.cnblogs.com/yoyoketang/p/11961988.html