前面用篇专门讲了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. JQuery选择器大全 前端面试送命题:面试题篇 对IOC和DI的通俗理解 c#中关于协变性和逆变性(又叫抗变)帮助理解

    JQuery选择器大全   jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#myELement")    选择id值等于myElement的元素 ...

  2. redis实践一些要注意的事项

    不要放垃圾数据,及时清理无用数据实验性的数据和下线的业务数据及时删除; key尽量都设置过期时间对具有时效性的key设置过期时间,通过redis自身的过期key清理策略来降低过期key对于内存的占用, ...

  3. pthread_create11121

    #include <stdlib.h> #include <stdio.h> #include <pthread.h> void* test(void* args) ...

  4. Vue 组件3 作用域插槽

    作用域插槽是一种特殊类型的插槽,用作使用一个(能够传递数据到)可重用模板替换已渲染元素. 在子组件中,只需将数据传递到插槽,就像你将props传递给组件一样: <div class=" ...

  5. dos2unix dos文本转换为linux文本 /bin/bas^M:bad interpreter

    第一种方法:dos2unix -f 文本名 第二种方法: 首先:vi 文本名 然后::set ff? 如果出现fileforma=dos那么就确定是linux和windows之间的不完全兼容 :set ...

  6. AFNet3.0上传图片

    很多iOS应用都会遇到需要上传图片的情况,比如修改个人资料时需要上传自己的头像,最近我也遇到了这种情况,首先参考之前写过的AFNetWorking3.0处理请求头和请求内容. 我们在上述博客的基础之上 ...

  7. Windows手动安装MySQL

    由于MySQL 5.6(也许5.5)以后去掉了Server Instance Configuration Wizard(服务实例配置向导),于是msi版变成了和zip版一样,要手动配置. * 假定安装 ...

  8. hdu 4272 LianLianKan 状态压缩

      LianLianKan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. Consul实现原理系列文章3: Consul的整体架构

    工作中用到了Consul来做服务发现,之后一段时间里,我会陆续发一些文章来讲述Consul实现原理.在前几篇文章介绍完了Consul用到的两个关键性东西Raft和Gossip之后,这篇文章会讲述Con ...

  10. Android 缓存详解目录

    1.http://www.cnblogs.com/lzrabbit/p/3734850.html 2.