目 录CONTENT

文章目录

locust登录及依赖接口压力测试

懿曲折扇情
2022-07-13 / 0 评论 / 3 点赞 / 79 阅读 / 456 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-07-13,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
广告 广告

一、locust登录及依赖接口压力测试

需求:

1.登录

2.change 接口下发

change_acl_mode.py

# coding=utf-8
"""
    @Project :pachong-master
    @File    :change_acl_mode.py
    @Author  :gaojs
    @Date    :2022/7/13 10:09
    @Blogs   : https://www.gaojs.com.cn
"""
from locust import HttpUser, between, task, TaskSet, tag
import os
# 强制去掉控制台InsecureRequestWarning
import urllib3
# 随机产生UA类库
from faker import Factory
urllib3.disable_warnings()


class TaskTest(TaskSet):

    def on_start(self):
        """
        description:每个用户执行此段代码
        :return:
        """
        # 每个用户执行此段代码
        print('==================== 清理log结束,压测开始, 登录虚拟站点并且 切换mode !!!========================')
        # pass

    # 压测任务,也可以是@task(10)啥的,这个数字是代表权重,数值越大,执行的频率就越高
    @task
    def stress_get(self):
        """
        请求httpbin
        :return:
        """
        url = '/prx/000/http/localh/login'
        data = {
            "Content-Type": "application/x-www-form-urlencoded, charset=UTF-8",
            'Connection': 'close',
            "method": "localdb",
            "uname": "test6",
            "pwd1": None,
            "pwd2": None,
            "pwd": "admin",
            "hardwareid: ": ""
        }
        randon_ua = Factory.create()
        ua = randon_ua.user_agent()
        headers = {
            'User-Agent': ua
        }
        rsp = self.client.post(url=url, headers=headers, data=data, verify=False, allow_redirects=False, name='loginVsite压测')
        # print(rsp.status_code)
        assert rsp.status_code == 302
        print(rsp.text)
        url_mode = 'https://192.168.120.65:555/prx/000/http/localhost/accessmode?modename=mode2'
        rsp1 = self.client.get(url=url_mode, name='访问模式切换')
        print(rsp1.status_code)
        assert rsp1.status_code == 200

    # 执行并发测试后执行的动作,比如保存log等操作,查看报告http://localhost:8089/
    def on_stop(self):
        pass


class UserBehavior(HttpUser):
    host = '192.168.120.65:555'
    # 每次请求停顿时间
    wait_time = between(3, 10)
    tasks = [TaskTest]


if __name__ == "__main__":
    os.system("locust -f change_acl_mode.py --host=https://192.168.120.65:555 --web-host=127.0.0.1")

image-1657686641092

二、运行及报告

image-1657686673105

image-1657686701385

image-1657686552833

image-1657686565706

image-1657686575763

3

评论区