前面用篇专门讲了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参数化的更多相关文章

  1. locust参数化(数据库取值)

    locust参数化(数据库取值) 基于上一篇参数化的梳理,本篇用另一种方法从数据库中取出这100个用户来登录 思路:在 TaskSet 中的 on_start 方法表示执行任务前的操作,可以将数据库取 ...

  2. Locust 参数化

    概述: 和Loadrunner一样对于多用户并发时,重复登入或者数据的重复使用会造成脚本的失败,那么我们引入Loadrunner的参数化概念,对用户数据进行参数化来使脚本运行成功. 头绪:   use ...

  3. python locust 性能测试:locust 参数化(list) ---循环取数据,数据可重复使用

    from locust import TaskSet, task, HttpLocust class UserBehavior(TaskSet): def on_start(self): # 当模拟用 ...

  4. 性能测试工具Locust

    An open source load testing tool. 一个开源性能测试工具. define user behaviour with python code, and swarm your ...

  5. Locust 性能测试工具安装使用说明

    1. 介绍     它是一个开源性能测试工具.使用 Python 代码来定义用户行为.用它可以模拟百万计的并发用户访问你的系统. 性能工具对比 LoadRunner 是非常有名的商业性能测试工具,功能 ...

  6. python locust 进行压力测试

    最近公司项目周期比较赶, 项目是软硬结合,在缺少硬件的情况下,通过接口模拟设备上下架和购买情况,并进行压力测试, 本次主要使用三个接口 分别是3个场景: 生成商品IP, 对商品进行上架, 消费者购买商 ...

  7. 性能测试进阶:(一)性能测试工具Locust

    An open source load testing tool. 一个开源性能测试工具. define user behaviour with python code, and swarm your ...

  8. 6000字Locust入门详解

    目录 一.Locust 性能测试 (一). 性能测试工具 主流性能测试工具对比 认识Locust (二) locust 基本用法 1.安装locust 2.编写用例 3. 启动测试 GUI 模式启动 ...

  9. python locust 性能测试:locsut参数化-保证并发测试数据唯一性,不循环取数据

    from locust import TaskSet, task, HttpLocustimport queue class UserBehavior(TaskSet): @task def test ...

随机推荐

  1. Python进行数值计算

    1.计算积分 (1)计算定积分 from scipy import integrate #定义函数def half_circle(x): return (1-x**2)**0.5 pi_half, e ...

  2. 关于struts、spring 和 hibernate的说明

    struts 是 web 框架 (jsp/action/actionfrom) hibernate 是 orm框架,处于持久层. spring 是容器框架,用于配置bean,并维护bean之间关系的框 ...

  3. 李洪强iOS开发之OC[006] - 类和对象

  4. virtualenv下使用matplotlib

    Unable to “import matplotlib.pyplot as plt” in virtualenv   (PyMVPA) SimilarFacedeMacBook-Pro:PyMVPA ...

  5. hud项目lcd调试

    lcd规格: 像素:480x280 bpp:16 pix_format:RGB565 在开发板终端中执行: ls /dev/fb0 -l ---> crw-rw----    1 root   ...

  6. 利用ascx输出knockoutjs的模板

    项目里面的UI模板在一个页面中有2K多行了.需要增加新的UI样式.问题来了.加上js代码,几乎是变成了不可维护的状态.增加和修改都需要用ctrl+f的方式找到对应的模板,然后进行处理.很容易出错.突然 ...

  7. latex math

    scalar -> lower case lettervector -> lower case bold lettermatrix -> upper case bold letter

  8. 如何使用qperf来衡量网络带宽和延迟性能?

    解析度 安装 qperf从RHEL服务器通道安装: 生的 # yum install qperf 检查带宽 服务器 让一个系统监听服务器: 生的 server # qperf 服务器默认在TCP端口1 ...

  9. Eclipse中关于JRE System Library、Web App Libraries的疑惑

    当我们在Eclipse中建立java的web工程时,会产生JRE System Library和Referenced Libraries,Web App Libraries不生成,下面会 简要说明一下 ...

  10. Java基础01 从HelloWorld到面向对象(转载)

    Java是完全面向对象的语言.Java通过虚拟机的运行机制,实现“跨平台”的理念. "Hello World!" public class HelloWorld{    publi ...