locust实现登录

可参考:https://www.it610.com/article/1393774645764771840.htm
import os,pytest
from locust import HttpUser,HttpLocust,FastHttpUser,constant,between,task,TaskSet,tag,SequentialTaskSet
import json
class AipTask(TaskSet):
wait_time = between(5,15)
@task
# 登录
def http_login(self):
header = {"Content-Type": "application/json;charset=UTF-8"}
payload ={"dlzh":"zhouf","password":"Z2lzbGlmZUAyMDIy","loginType":1}
respons = self.client.post('http://192.168.1.235:8989/disaster/login',data=json.dumps(payload),headers = header,verify=False)
print("Response json:", respons.json())
# print(respons.status_code)
# print(respons.json())

class WebsiteUser(HttpUser):
tasks = [AipTask]
min_wait = 1000
max_wait = 2000
if __name__ == '__main__':
os.system('locust -f day3.py')
posted @ 2022-06-30 15:26  GoodMorning9527  阅读(103)  评论(0)    收藏  举报