zoukankan      html  css  js  c++  java
  • Python locust性能测试框架模板

    locust框架模板

    from locust import HttpLocust, TaskSet, task
    import Queue
    
    
    class UserBehavior(TaskSet):
    
        def setup(self):
            print('task setup')
    
        def teardown(self):
            print('task teardown')
    
        def on_start(self):
    
            # key = self.login()
            request_url = "/api/user/getkey"
            request_json = {"username": "qxzn", "userpwd": "qx6688"}
    
            response = self.client.post(url=request_url, json=request_json)
            # print response.status_code
            # print response.text
            if response.status_code != 200:
                print u"返回异常,请求返回状态码:", response.status_code
            elif response.status_code == 200:
                print u"返回正常:", response.status_code
            global key_1, key_2
            key_1 = response.text.split('''appkey":"''')[1].split('"')[0]
            key_2 = response.text.split('''infokey":"''')[1].split('"')[0]
            print key_1 + '-' + key_2
            data = self.locust.user_data_queu
            print data
    
        def on_stop(self):
            # 虚拟用户结束Task时运行
            print('end')
    
        @task(1)
        def resList(self):
    
            # key = self.login()
            header = {'Accept': 'application/json, text/plain, */*',
                      'Accept-Encoding': 'gzip, deflate',
                      'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
                      'Connection': 'keep-alive',
                      'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0',
                      'Content-Type': 'application/json;charset=utf-8',
                      'Authorization': key_1 + '-' + key_2}
            data = {"num": 15, "current_page": 1, "province": "", "city": "", "type": ""}
            request_url = "/api/desk_device/devicelist"
    
            response = self.client.post(url=request_url, headers=header, json=data)
            if response.status_code != 200:
                print u"返回异常,请求返回状态码:", response.status_code
            elif response.status_code == 200:
                print u"返回正常", response.status_code
    
    
    class WebsiteUser(HttpLocust):
    
        def setup(self):
            print('locust setup')
    
        def teardown(self):
            print('locust teardown')
    
        user_data_queue = Queue.Queue()
        task_set = UserBehavior
        host = "http://xxxx.com:8095"
        min_wait = 5000
        max_wait = 8000
  • 相关阅读:
    SAP 多料号展BOM
    SAP QM 检验批可用库存回转为待检验库存
    SAP QM UD检验批回转为REL待检验状态
    在ABAP中获取应用程序服务器的IP地址
    SAP连接外部数据库后批量写入数据
    Java调用Axis2用SAP WSDL生成的Stub文件
    用最新的采购信息记录更新采购单的价格——BAPI_PO_CHANGE
    SAP QM——QA01、QA02、QA03屏幕增强
    Java递归实现一、二、三级菜单查询
    ABAP——查询
  • 原文地址:https://www.cnblogs.com/monogem/p/11367943.html
Copyright © 2011-2022 走看看