一、locust 实例中的self.client 指向了HTTPsession 类,只要服务端返回了cookie,默认就是可以自动处理cookie的
代码如下:
from locust import HttpUser, TaskSet, task, os class MyTask(TaskSet): def on_start(self): self.data1 = {"userName": "admin", "password": "1234"} response = self.client.post("/pinter/bank/api/login", data=self.data1, name="login") print(response.text) def on_stop(self): print("用户结束") @task def query_account(self): self.data2 = {"userName": "admin"} response = self.client.get("/pinter/bank/api/query", params=self.data2, name="quer_account") print(response.text) class WebsiteUser(HttpUser): tasks = [MyTask] host = "http://lcocalhost:8080" min_wait = 5000 max_wait = 9000 if __name__ == "__main__": os.system("locust -f CookieTest.py --host=http://localhost:8088")