python locust提取参数_python locust 性能测试:locust 关联---提取返回数据并使用

from locust import HttpLocust, TaskSet, task

import json

from common import readConfig

class UserBehavior(TaskSet): # 定义用户行为

def on_start(self): # 当模拟用户开始执行TaskSet类的时候,on_start方法会被调用

pass def get_headers(self):   """会员登录""" headers = { "Content-Type": "application/json", "channel": "SHOP" } body = { "unionid": readConfig.unionid # 这样使用会报错,没有 common ... } res = self.client.post(‘/customers/login‘, headers=headers, data=json.dumps(body)).text assert ‘成功‘ in res # 断言,判断接口返回是否成功 res = json.loads(res) uid = res[‘data‘][‘uid‘] ukey = res[‘data‘][‘ukey‘] return [uid, ukey] # 会员登录返回的uid和ukey @task(1) # @task() 装饰该方法为一个任务;1表示一个Locust实例被挑选执行的权重,数值越大,执行频率越高; def members_can_withdraw_account_information(self): # 一个行为 """使会员获取会员状态""" res = self.get_headers() headers = { "channel": "SHOP", "uid": str(res[0]), "ukey": res[1] } response = self.client.put("/customers/customer_state", headers=headers).text # client.get()用于指请求的路径,可加headers,params,body参数; assert ‘成功‘ in response @task(1) def get_member_account_withdrawal_details(self): """获取会员账户提现明细""" res = self.get_headers() headers = { "channel": "SHOP", "uid": str(res[0]), "ukey": res[1] } params = { "page": "10", "size": "10" } response = self.client.get("/customers/account/withdraw/log", headers=headers, params=params).text assert ‘成功‘ in responseclass WebsiteUser(HttpLocust): # 设置性能测试; host = "http://dev.sign.lixiaofeng.com" task_set = UserBehavior # 指向一个定义了的用户行为类; min_wait = 3000 # 用户执行任务之间等待时间的下界,单位:毫秒; max_wait = 6000 # 用户执行任务之间等待时间的上界,单位:毫秒;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值