from locust import HttpLocust,TaskSet,task import os class UserBehavior(TaskSet): @task def login(self): # 登录URL loginUrl = '/login' h = { "User-Agent":"Mozilla / 5.0(Windows NT 10.0;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 78.0.3904 .87 Safari / 537.36", "Content-Type":"multipart/form-data; boundary=----WebKitFormBoundarytSE9CWoPfB1aHYdw" } r = self.client.post(loginUrl,headers=h) print(r.text) assert '登录成功!'in r.text class LoginUser(HttpLocust): task_set = UserBehavior min_wait = 1000 # 用户等待时间的下界(ms) max_wait = 3000 # 用户等待时间的上界 if __name__ == '__main__': os.system("locust -f LOGINTEST.py --host=https://xxx.cn")