zoukankan      html  css  js  c++  java
  • locust -基础框架

    # coding=utf-8
    from locust import HttpLocust, TaskSet, task
    import requests

    # 定义用户行为
    class UserBehavior(TaskSet):

      @task
      def baidu_index(self):
      #请求参数
        payload = {'mobile':'12615990003','password':'ef797c8118f02dfb649607dd5d3f8c7623048c9c063d532cc95c5ed7a898a64f'}
      #请求头
        headers = {
          'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
          'Content-Type': "application/x-www-form-urlencoded",
          'version': "2.0.0",
          'Accept': "*/*",
          'version-id': "200",
          'Postman-Token': "01f92812-7bdc-4c6e-a3b8-72f0381dc012"
            }
          #模拟请求
        a=self.client.post("/user/login",data=payload, headers=headers,catch_response = True,verify=False)

        #断言
          if 'SUCCESS' in a.text:
            a.success()   # 需要加catch_response

          else:

            a.failure("Got wrong response")        

    class WebsiteUser(HttpLocust):
      task_set = UserBehavior
      min_wait = 3000
      max_wait = 6000

    if __name__ == "__main__":
      import os
      os.system("/usr/local/bin/locust -f /Users/kaibinliu/Desktop/rubbish/Locust/load_test.py --host=https://www.weixiao.qq.com")

    在浏览器打开:localhost:8089

    参考:https://www.cnblogs.com/imyalost/p/9758189.html

    后记:

    可以把host放到WebsiteUser类里面,敲命令可以敲少一点

     参考https://blog.csdn.net/panyu881024/article/details/80146074

     

  • 相关阅读:
    ASP.NET教程4
    ASP.NET教程11
    TreeView Demo
    System.Net.Dns.GetHostByAddress(string) 已经过时
    会员注册实例
    ASP.NET教程2
    多表关联与表值函数
    ASP.NET教程6
    BusinessFrameWork
    ASP.NET教程8
  • 原文地址:https://www.cnblogs.com/kaibindirver/p/10666081.html
Copyright © 2011-2022 走看看