使用Locust遇到的问题

一、locust版本0.13之后已经废除了min_wait和max_wait的使用

    min_wait = 3000
    max_wait = 7000

改为使用

wait_time = between(3,7)

官方说明:
在这里插入图片描述

二、request参数catch_response的使用

官方说明:
在这里插入图片描述
简单来讲,如果需要locust中的Fails正常记录到错误的信息,就需要使用catch_response来捕获请求,将其标记为成功或者失败
在这里插入图片描述
实现代码如下:

    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("请求失败")

官方关于success与failure的解说:
在这里插入图片描述

三、post请求参数的说明

先说说遇到的问题,我使用了三种传参,得到的提示如图

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)

在这里插入图片描述
最后我换成json成功了

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

官方说明:
在这里插入图片描述

四、执行顺序

官网说明:
在这里插入图片描述

五、执行程序

官网说明(谷歌翻译的结果):
在这里插入图片描述
实例:

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)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值