登录案例locustfile.py
2024-09-03 13:47:53
# 保存为locustfile.py
# coding=utf-8
from locust import HttpLocust, TaskSet, task
'''
实现场景:先登录(只登录一次),然后访问->我的地盘页->产品页->项目页
访问我的地盘页面权重为2,产品页和项目页权重各为1
'''
class UserBehavior(TaskSet):
'''蝗虫行为类'''
def _login(self):
'''登录方法'''
# host = 'http://192.168.x.xx:80' # 禅道的服务器地
loginUrl ="/zentao/user-login.html/"
h = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0",
"Content-Type": "application/x-www-form-urlencoded",
}
body = {"account": "运营", # 你自己的账号
"password": "******", # 你自己的密码
"keepLogin[]": "on",
"referer": "/zentao/my/"
}
r = self.client.post(loginUrl, data=body, headers=h)
print(r.text)
assert "parent.location='/zentao/index.html'" in r.text
def on_start(self):
'''任务开始准备工作:只登录一次'''
self._login()
# 任务1-我的地盘
@task(2)
def zentao_my(self):
print("---访问页面-我的地盘---")
r = self.client.get("/zentao/my/")
assert "我的地盘" in r.text
# 任务2-产品页
@task(1)
def zentao_product(self):
print("---访问页面-产品页---")
r = self.client.get("/zentao/product-browse.html/")
assert "需求列表" in r.text
# 任务3-项目
@task(1)
def zentao_prject(self):
print("---访问页面-项目---")
r = self.client.get("/zentao/project/")
assert "项目首页" in r.text
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 1000
max_wait = 1000
if __name__ == "__main__":
import os
os.system("locust -f locustfile.py --host=http://192.168.x.xx:80")
最新文章
- android_studio上传svn的时候那些不提交
- Linux下通配符总结
- ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS
- android setLayoutParams 问题,出错
- 常见错误:Apple Mach-O Linker Error
- codeforces 468B 2-sat
- UVA 12627 - Erratic Expansion
- node 与php整合
- MySQL 学习笔记 (limit offset)
- SQL Mon 介绍
- Windows下检测文件名大小写是否匹配
- 从java的开始,java概述,java配置环境变量
- Java基础day01
- vc关于大文件读写
- weblogic11,linux字符页面安装
- 使用generator生成dao、mapping和model
- [UE4]蓝图比C++慢10倍,是吗?
- 【转】Spring、Spring MVC、MyBatis整合文件配置详解
- 发布MVC项目到服务器上时候遇到的 模块 DirectoryListingModule 通知 ExecuteRequestHandler 处理程序 StaticFile 错误代码 0x00000000
- kubeadm init 时从本地私有仓库下载镜像