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 ...
随机推荐
- 680. Valid Palindrome II【easy】
680. Valid Palindrome II[easy] Given a non-empty string s, you may delete at most one character. Jud ...
- grub的三种安装方式
1.install命令 install: install [--stage2=STAGE2_FILE] [--force-lba] STAGE1 [d] DEVICE STAGE2 [ADDR] [p ...
- BZOJ 1260 CQOI2007 涂色paint 动态规划
题目大意:给定一块木板,上面每一个位置有一个颜色,问最少刷几次能达到这个颜色序列 动态规划,能够先去重处理(事实上不是必需),令f[i][j]代表将i開始的j个位置刷成对应颜色序列的最小次数.然后状态 ...
- java字符串和时间类型的相互转换
整理的时间正则可能不全 /****** * * 是以"-" 为分隔符的 * * * * ******/ // 2012-12-03 04:07:34 reg = "\\d ...
- Python 2.7 中使用 Print 方法
print ("test",file=name)类似的方法在python 2中需要先引入 __future__才可使用 import __futhure__ import prin ...
- Ext扩展的QQ表情选择面板
Ext扩展的QQ表情选择面板 define(function () { EmoteChooser = function(cfg){ this.width=340; this.height=112; t ...
- 第一百九十六节,jQuery EasyUI,Tooltip(提示框)组件
jQuery EasyUI,Tooltip(提示框)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Tooltip(提示框)组件的使用方法, ...
- Spring MVC单选按钮
以下示例显示如何在使用Spring Web MVC框架的表单中使用单选按钮(RadioButton).首先使用Eclipse IDE来创建一个WEB工程,并按照以下步骤使用Spring Web Fra ...
- python requests.exceptions.ConnectionError
今天遇到一个奇葩问题, 1.r.request.post(url) 2..print r. status_code 居然第一步就报错了,原因是url不正确,按道理应该可以走到第二步然后输入404的 i ...
- python3----字符串中的字符倒转
方法一,使用[::-1]: s = 'python' print(s[::-1]) 方法二,使用reverse()方法: n = list(s) n.reverse() print(''.join(n ...