我想从Locust中运行多个负载测试,例如测试前端和后端。我想知道是否可以从单个蝗虫文件中执行此操作,但通过我想在locust -f locustfile.py --host=<host>
中作为参数运行的测试。
答案 0 :(得分:0)
使用@task装饰器,它将在此处运行每个示例代码
# The multiple uer login script with - https://opensource-demo.orangehrmlive.org
from locust import HttpUser, TaskSet,task,between
class UserBehaviour(TaskSet):
@task(1)
def login_post(self):
print("from user 1 logining in")
resp = self.client.post("/index.php/auth/login",data={"action": "process","userName": "Admin","password": "admin123" , "_csrf_token": " f28bb18622cc82a56c41be5f7de07690"})
print(resp.status_code)
@task(1)
def load_dashboard(self):
print("from user 2")
resp = self.client.get("/webres_5f61a473615588.75870608/orangehrmDashboardPlugin/js/graph-visualizer/pie-chart.js")
self.client.get("/webres_5f61a473615588.75870608/orangehrmDashboardPlugin/js/flot/JUMFlot.min.js")
self.client.get("/webres_5f61a473615588.75870608/orangehrmDashboardPlugin/js/flot/jquery.flot.pie.min.js")
self.client.get("/index.php/dashboard/employeeDistribution")
print(resp.status_code)
@task(1)
def apply_leave(self):
print("from user 3")
resp = self.client.get("/index.php/leave/getWorkWeekAjax?_=1602164350152")
self.client.get("/index.php/leave/getHolidayAjax?year=2020&_=1602164350151")
self.client.get("/index.php/leave/getLeaveBalanceAjax?&leaveType=1&startDate=yyyy-mm-dd&endDate=yyyy-mm-dd")
self.client.get("/index.php/leave/getLeaveBalanceAjax?&leaveType=1&startDate=2020-10-09&endDate=2020-10-09")
self.client.get("/index.php/leave/getLeaveBalanceAjax?&leaveType=1&startDate=2020-10-09&endDate=2020-10-16")
print(resp.status_code)
class User(HttpUser):
tasks=[UserBehaviour]
wait_time = between(5000, 10000)
host="https://opensource-demo.orangehrmlive.com"