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
@t