参数化传入多组数据
# 针对注册功能进行性能测试
from locust import HttpLocust,task,TaskSet
class UserBehavior_reg(TaskSet):
@task
def test_reg(self):
# 构造测试数据
for i in range(10,21):
user="test"+str(i)
regdata={"email":user+"@qq.com",
"username":user,
"password":"123456",
"repassword":"123456",
"captcha":"12345"}
response=self.client.post("/index.php?controller=simple&action=reg_act",data=regdata).text
# print(response)
loc=response.find("恭喜")
if loc>=0:
print(user+"注册测试成功")
else:
print(user+"注册测试失败")
class webSiteUser(HttpLocust):
host = "http://localhost:8085/iwebshop"
task_set = UserBehavior_reg
min_wait = 2000
max_wait = 5000