Problems encountered in using Locust

A, locust after version 0.13 has abolished the use of min_wait and max_wait

    min_wait = 3000
    max_wait = 7000

Instead, use

wait_time = between(3,7)

The official explanation:
Here Insert Picture Description

Two, request parameters using catch_response

Official Description:
Here Insert Picture Description
Simply put, if you need locust in Fails to record the normal error message, you need to use catch_response to capture the request, it is marked as a success or failure
Here Insert Picture Description
codes are as follows:

    def on_start(self):
        body = {"username":"scqy1","password":"123123"}
        response = self.client.post("http://10.46.59.15/login",json=body,catch_response=True)
        # 解析响应的json数据,后续就可以正常使用列表或者字典操作数据
        newText = json.loads(response.text)
        self.token = newText["result"]["token"]
        if newText["code"] == 0:
            response.success()
        else:
            response.failure("请求失败")

The official explanation about the success and failure:
Here Insert Picture Description

Three, post request description of the parameters

First talk about the problems encountered, I used three parameter passing, get tips Figure

self.client.post("http://10.46.59.156:8002/login",body)
self.client.post("http://10.46.59.156:8002/login",body=body)
response = self.client.post("http://10.46.59.156:8002/login",data=body)

Here Insert Picture Description
Finally, I succeeded into json

response=self.client.post("http://10.46.59.156:8002/login",json=body)

The official explanation:
Here Insert Picture Description

Fourth, the execution order

Official website Description:
Here Insert Picture Description

Fifth, the implementation of the program

Official website Description (results Google Translation):
Here Insert Picture Description
Example:

class Run_test(HttpLocust):
    # 此处必须使用task_set,否则会提示No Locust class found!
    task_set = Test_yl
    #此处必须使用between的方法,min_wait和的用法max_wait在0.13版本之后就被弃用了
    wait_time = between(3, 7)
Published 44 original articles · won praise 1 · views 1481

Guess you like

Origin blog.csdn.net/cc_park/article/details/103605167