locust参数化
前面用篇专门讲了requests实现接口的参数关联案例,这里直接转化成locust脚本就行了
# coding:utf-8
from locust import HttpLocust, TaskSet, task
from lxml import etree
class LoginDemo(TaskSet):
    '''用户行为描述'''
    def get_it_execution(self):
        result = {}
        h1 = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
        }
        self.client.headers.update(h1)
        r = self.client.get("/passport/login", verify=False)
        # 从返回html页面,解析出lt、execution
        dom = etree.HTML(r.content.decode("utf-8"))
        try:
            result["lt"] = dom.xpath('//input[@name="lt"]')[0].get("value")
            result["execution"] = dom.xpath('//input[@name="execution"]')[0].get("value")
            print(result)
        except:
            print("lt、execution参数获取失败!")
        return result
    def login(self, user, psw):
        result = self.get_it_execution()
        loginurl = "/passport/login"
        h2 = {
            "Referer": loginurl,
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
            "Origin": "https://account.chsi.com.cn",
            "Content-Length": "119",
            "Cache-Control": "max-age=0",
            "Upgrade-Insecure-Requests": "1",
            "Content-Type": "application/x-www-form-urlencoded"
            }
        body = {
            "username": user,
            "password": psw,
            "rememberMe": "true",
            "lt": result["lt"],
            "execution": result["execution"],
            "_eventId": "submit"
        }
        self.client.headers.update(h2)
        print(self.client.headers)
        r1 = self.client.post(loginurl, data=body, verify=False)
        # print(r1.text)
    @task(1)
    def test_login(self):
        # 测试数据
        user = "13888888888"
        psw = "111111"
        self.login(user, psw)
class websitUser(HttpLocust):
    task_set = LoginDemo
    host = "https://account.chsi.com.cn"
    min_wait = 3000  # 单位毫秒
    max_wait = 6000  # 单位毫秒
if __name__ == "__main__":
    import os
    os.system("locust -f locustfile3.py")locust参数化的更多相关文章
- locust参数化(数据库取值)
		locust参数化(数据库取值) 基于上一篇参数化的梳理,本篇用另一种方法从数据库中取出这100个用户来登录 思路:在 TaskSet 中的 on_start 方法表示执行任务前的操作,可以将数据库取 ... 
- Locust 参数化
		概述: 和Loadrunner一样对于多用户并发时,重复登入或者数据的重复使用会造成脚本的失败,那么我们引入Loadrunner的参数化概念,对用户数据进行参数化来使脚本运行成功. 头绪: use ... 
- python locust 性能测试:locust 参数化(list) ---循环取数据,数据可重复使用
		from locust import TaskSet, task, HttpLocust class UserBehavior(TaskSet): def on_start(self): # 当模拟用 ... 
- 性能测试工具Locust
		An open source load testing tool. 一个开源性能测试工具. define user behaviour with python code, and swarm your ... 
- Locust 性能测试工具安装使用说明
		1. 介绍 它是一个开源性能测试工具.使用 Python 代码来定义用户行为.用它可以模拟百万计的并发用户访问你的系统. 性能工具对比 LoadRunner 是非常有名的商业性能测试工具,功能 ... 
- python locust 进行压力测试
		最近公司项目周期比较赶, 项目是软硬结合,在缺少硬件的情况下,通过接口模拟设备上下架和购买情况,并进行压力测试, 本次主要使用三个接口 分别是3个场景: 生成商品IP, 对商品进行上架, 消费者购买商 ... 
- 性能测试进阶:(一)性能测试工具Locust
		An open source load testing tool. 一个开源性能测试工具. define user behaviour with python code, and swarm your ... 
- 6000字Locust入门详解
		目录 一.Locust 性能测试 (一). 性能测试工具 主流性能测试工具对比 认识Locust (二) locust 基本用法 1.安装locust 2.编写用例 3. 启动测试 GUI 模式启动 ... 
- python locust 性能测试:locsut参数化-保证并发测试数据唯一性,不循环取数据
		from locust import TaskSet, task, HttpLocustimport queue class UserBehavior(TaskSet): @task def test ... 
随机推荐
- 构建基于Javascript的移动web CMS入门——简单介绍
			看到项目上的移动框架,网上寻找了一下,发现原来这些一開始都有. 于是,找了个演示样例開始构建一个移动平台的CMS--墨颀 CMS,方便项目深入理解的同一时候.也能够自己维护一个CMS系统. 构建框架 ... 
- mybatis学习笔记(14)-查询缓存之中的一个级缓存
			mybatis学习笔记(14)-查询缓存之中的一个级缓存 标签: mybatis mybatis学习笔记14-查询缓存之中的一个级缓存 查询缓存 一级缓存 一级缓存工作原理 一级缓存測试 一级缓存应用 ... 
- [容器]gcr.io镜像下载
			下载gcr.io的镜像hosts文件 把下面两行加入到/etc/hosts中. 更多在这里http://wst.so/files/hosts 61.91.161.217 gcr.io 61.91.1 ... 
- Python内置函数之ascii()
			ascii()返回一个字符串对象. ascii()的参数只能有一个. 如果参数中有非ascii字符,会用 \u,\U,\x 来替代. ascii()和Python2中repr()等效 下面看看例子: ... 
- Netbeans取消CTRL+\才能代码提示的方法
			更好的方法: ------------------------------------------------------------ 边打字边按CTRL+\进行代码提示的方法我TM也是醉了 简而言之 ... 
- python简单处理xml文件
			Python若是想从xml里读点信息,用BeautifulSoup可能会容易一点,但是如果要修改xml,BeatifulSoup就搞不定了,其实直接用lxml就好. from lxml import ... 
- centos6 找不到 phpize
			安装php-devel yum install php-devel.i686 
- nginx源代码分析--nginx模块解析
			nginx的模块很之多.能够觉得全部代码都是以模块的形式组织.这包含核心模块和功能模块,针对不同的应用场合.并不是全部的功能模块都要被用到,附录A给出的是默认configure(即简单的httpser ... 
- mysql explain的解释
			详解MySQL中EXPLAIN解释命令 explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上e ... 
- vSphere共享存储全配置流程
			1.Openfiler的安装 Openfiler 由rPath Linux驱动,它是一个基于浏览器的免费网络存储管理实用程序,可以在单一框架中提供基于文件的网络连接存储 (NAS) 和基于块的存储区域 ... 
