前言

前面【Locust性能测试2-先登录场景案例】讲了登录的案例,这种是直接传账号和密码就能登录了,有些登录的网站会复杂一点,
需要先从页面上动态获取参数,作为登录接口的请求参数,如【学信网:https://account.chsi.com.cn/passport/login】的登录接口请求参数

请求参数

需要先发个get请求,从返回的html页面中解析出需要的数据

  • lt : LT-277623-5ldGTLqQhP4foKihHUlgfKPeGGyWVI
  • execution: e1s1

备注:
lt 参数是每次打开浏览器,访问登录首页时服务端会返回一个新的数据
execution 参数是表示网站刷新次数,可以刷新下再登录,就变成 e2s1了

<input class="btn_login" name="submit" accesskey="l" value="登录" tabindex="" type="submit" title="登录" />

<div class="account-oprate clearfix">
<a class="find-yhm" href="https://account.chsi.com.cn/account/password!rtvlgname">找回用户名</a>
<a class="find-mm" href="https://account.chsi.com.cn/account/password!retrive">找回密码</a>
<a href="https://account.chsi.com.cn/account/preregister.action?from=account-login" class="regist-btn">注册</a>
</div>
<input type="hidden" name="lt" value="LT-279621-fnisPBt0FVGNFrfWzJJqhTEyw6VkfH" />
<input type="hidden" name="execution" value="e2s1" />
<input type="hidden" name="_eventId" value="submit" />

locustfile3.py代码

前面用篇专门讲了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": "",
"Cache-Control": "max-age=0",
"Upgrade-Insecure-Requests": "",
"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 = ""
psw = ""
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性能测试4-参数关联

    前言 前面[Locust性能测试2-先登录场景案例]讲了登录的案例,这种是直接传账号和密码就能登录了,有些登录的网站会复杂一点, 需要先从页面上动态获取参数,作为登录接口的请求参数,如[学信网:htt ...

  2. Locust性能测试_先登录场景案例

    前言 有很多网站不登录的话,是无法访问到里面的页面的,这就需要先登录了实现场景:先登录(只登录一次),然后访问页面->我的地盘页->产品页->项目页 官方案例 下面是一个简单的loc ...

  3. Locust性能测试_百度案例

    一.安装: 1.Locust在PyPI上可用,可以通过pip或easy_install安装:pip install locustio                2.查看Locust可用选项:loc ...

  4. Locust性能测试

    https://www.cnblogs.com/yoyoketang/p/9638151.html https://www.cnblogs.com/yoyoketang/p/9642242.html ...

  5. python locust 性能测试:locust安装和一些参数介绍

    安装参考 https://www.cnblogs.com/fnng/p/6081798.html <虫师大大的,很详细> ps:python3.7暂不支持locust:python3安装建 ...

  6. locust参数关联及批量注册

    前言 前面[Locust性能测试2-先登录场景案例]讲了登录的案例,这种是直接传账号和密码就能登录了,有些登录的网站会复杂一点,需要先从页面上动态获取参数,作为登录接口的请求参数,如[学信网:http ...

  7. Locust性能测试6-命令行参数详解

    前言 当我们在linux上使用locust工具压测的时候,会使用no-web模式,然后需要收集运行的日志,方便查找问题. 命令行参数 输入locust --help 查看所有的命令行参数 > l ...

  8. Python Locust性能测试框架实践

    [本文出自天外归云的博客园] Locust的介绍 Locust是一个python的性能测试工具,你可以通过写python脚本的方式来对web接口进行负载测试. Locust的安装 首先你要安装pyth ...

  9. 软件测试_Loadrunner_APP测试_性能测试_脚本优化_脚本回放

    本文主要写一下在使用Loadrunner录制完毕APP脚本之后如何对脚本进行回放,如有不足,欢迎评论补充. 如没有安装Loadrunner软件,请查看链接:软件测试_测试工具_LoadRunner: ...

随机推荐

  1. Xilinx ISE中Synplicity.ucf无法加上去的问题

    在Xilinx ISE中使用Synplify pro进行综合时,有时出现无法将synplicity.ucf添加进工程的问题.这时可以在其它目录下备份synplicity.ucf, 然后使用clean ...

  2. Spring通知,顾问,增强

    1.AOP  (Aspect  Oriented Programming  面向切面编程) 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编 ...

  3. gcc 编译c++文件

    #include <stdio.h> //将类定义在命名空间中 namespace Diy{ class Student{ public: char *name; int age; flo ...

  4. mfs分布式文件系统,分布式存储,高可用(pacemaker+corosync+pcs),磁盘共享(iscsi),fence解决脑裂问题

    一.MFS概述 MooseFS是一个分布式存储的框架,其具有如下特性:(1)通用文件系统,不需要修改上层应用就可以使用(那些需要专门api的dfs很麻烦!).(2)可以在线扩容,体系架构可伸缩性极强. ...

  5. Eclipse 远程开发插件 RSE 及远程登录

    Eclispe 使用私钥登录远程服务器 生成私钥 Window --> Preference --> SSH2 --> Key Management --> Generate ...

  6. 第08组 Beta冲刺(1/4)

    队名 八组评分了吗 组长博客链接(2分) 小李的博客 作业链接 组员1李昕晖(组长) 过去两天完成了哪些任务 文字/口头描述 12月3号了解各个小组的进度与难以攻破的地方,晚上安排开会,安排新的冲刺任 ...

  7. 剑指offer:数据流中的中位数

    题目描述: 如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值.如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值.我 ...

  8. html5 input number类型使用整理

      一.  html5 input中的数字number类型, 只能输入整数,如果要输入浮点数呢,可以通过max.min和step去定义. type="number" 数字类型 mi ...

  9. Windows Server 2008 + IIS 7+ ASP.NET 并发优化

    Windows Server 2008 + IIS 7+ ASP.NET 并发优化 站点出现这样的错误信息: Error Summary: HTTP Error 503.2 - Service Una ...

  10. List和数组的互转

    list转数组: /要转换的list集合 List<String> testList = new ArrayList<String>(){{add("aa" ...