# 保存为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")

最新文章

  1. android_studio上传svn的时候那些不提交
  2. Linux下通配符总结
  3. ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS
  4. android setLayoutParams 问题,出错
  5. 常见错误:Apple Mach-O Linker Error
  6. codeforces 468B 2-sat
  7. UVA 12627 - Erratic Expansion
  8. node 与php整合
  9. MySQL 学习笔记 (limit offset)
  10. SQL Mon 介绍
  11. Windows下检测文件名大小写是否匹配
  12. 从java的开始,java概述,java配置环境变量
  13. Java基础day01
  14. vc关于大文件读写
  15. weblogic11,linux字符页面安装
  16. 使用generator生成dao、mapping和model
  17. [UE4]蓝图比C++慢10倍,是吗?
  18. 【转】Spring、Spring MVC、MyBatis整合文件配置详解
  19. 发布MVC项目到服务器上时候遇到的 模块 DirectoryListingModule 通知 ExecuteRequestHandler 处理程序 StaticFile 错误代码 0x00000000
  20. kubeadm init 时从本地私有仓库下载镜像

热门文章

  1. VS2015 解决方案 或者项目 卡 正在加载 的解决办法
  2. Angular 2 组件之间如何通信?
  3. Atitit.自定义jdbc驱动  支持jsql
  4. MySQL:系列合集
  5. C语言基础(13)-函数
  6. Android 之布局
  7. Unity3d中模型导入轴向不对的解决方法
  8. 设计模式中类的关系之聚合关系(Aggregation)
  9. C# WEB 不显示目录结构
  10. error: not found: value sc