51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1722|回复: 2
打印 上一主题 下一主题

Locust 脚本-HttpLocust

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-3-22 16:43:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
HttpLocust类比Locust类多了client特性,而Locust内部其实使用了python的requests模块发送HTTP请求,所以HTTP响应类的特性及方法也十分类似
  1. from locust import HttpLocust, TaskSet, task, events
  2. import requests

  3. class UserBehavior(TaskSet):

  4.         def login(self):
  5.                 a = requests.post("https://xxx.xxxxxxx.com/?c=login&m=login",{"username":"test1","password":"123456"})
  6.                 ck = a.cookies
  7.                 return ck

  8.         @task
  9.         def profile1(self):
  10.                 b = self.client.get("/",cookies=self.login())
  11.                 print(dir(b))
复制代码
  1. ['__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__doc__',
  2. '__enter__', '__exit__', '__format__', '__getattribute__', '__getstate__',
  3. '__hash__', '__init__', '__iter__', '__module__', '__new__', '__nonzero__',
  4. '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__',
  5. '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_content',
  6. '_content_consumed', '_next', 'apparent_encoding', 'close', 'connection',
  7. 'content', 'cookies', 'elapsed', 'encoding', 'headers', 'history',
  8. 'is_permanent_redirect', 'is_redirect', 'iter_content', 'iter_lines',
  9. 'json', 'links', 'next', 'ok', 'raise_for_status', 'raw', 'reason',
  10. 'request', 'status_code', 'text', 'url']



  11. 常用方法

  12. b.cookies   
  13. b.json()
  14. b.status_code
  15. b.text
  16. b.history
  17. b.reason
  18. b.encoding
  19. b.headers
复制代码
使用cookie,和requests类时一样,当做参数传给get、post即可
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-4-26 12:55 , Processed in 0.069145 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表