当前位置:网站首页>Locust performance test 2 (interface request)
Locust performance test 2 (interface request)
2022-07-07 09:08:00 【Song_ Lun】
Have been to Loust With a basic understanding of , Next, you can make an interface request
One 、 Post request
The user login
According to business needs , The login interface is executed only once , stay on_start() Function to write login information
class MyTasks(TaskSet):
url = '/login'
headers = {
'Content-Type': 'application/json'}
def on_start(self):
self.data = {
"username":"admin","password":"123456"}
respon = self.client.post(self.url, headers = self.headers, data=json.dumps(self.data), name=' The user login ', verify=False, timeout=10)
resp_dict = respon.json()
# print(f' The response data is :{resp_dict}')
if respon.status_code == 200:
# Interface success
print(resp_dict['msg'])
else:
# request was aborted
respon.failure(resp_dict['msg'])
class User(HttpUser):
tasks = [MyTasks]
host = 'https://www.baidu.com'
wait_time = between(2,2) # Every time 2 Once per second
Two 、 Get request
Send mobile phone verification code
from locust import HttpUser, TaskSet, task
''' get Request interface '''
class MyTasks(TaskSet):
url = '/xxx/xxx/sendAuthCode'
headers = {
'Content-Type': 'application/json',
'Authorization': 'xxxxx'
}
def on_start(self):
print(" User initialization -- Sign in ")
@task
def get_login(self):
print(' Send verification code ...')
# Define an object property
self.query_data = {
'mobile': 1579715000}
respon = self.client.get(self.url, params = self.query_data, headers = self.headers, name=' Send verification code ', verify=False, timeout=10)
resp_dict = respon.json()
print(f' The response data is :{
resp_dict}')
边栏推荐
- Simulation volume leetcode [general] 1567 Length of the longest subarray whose product is a positive number
- Output all composite numbers between 6 and 1000
- [istio introduction, architecture, components]
- Digital triangle model acwing 1027 Grid access
- UnityShader入门精要个人总结--基础篇(一)
- 模拟卷Leetcode【普通】1706. 球会落何处
- LeetCode 715. Range 模块
- Count the number of words C language
- What is the value of getting a PMP certificate?
- What are the conditions for applying for NPDP?
猜你喜欢
Three updates to build applications for different types of devices | 2022 i/o key review
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
Why is access to the external network prohibited for internal services of the company?
JVM garbage collection detailed learning notes (II)
MySQL master-slave delay solution
Common short chain design methods
Markdown editor Use of MD plug-in
How long does the PMP usually need to prepare for the exam in advance?
MySQL主从延迟的解决方案
Mountaineering team (DFS)
随机推荐
Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
实现自定义内存分配器
H3C vxlan configuration
C语言指针(中篇)
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
Port occupation troubleshooting
Why is access to the external network prohibited for internal services of the company?
Un salaire annuel de 50 W Ali P8 vous montrera comment passer du test
Goldbach conjecture C language
STM32的时钟系统
寄存器地址名映射
徽商期货公司评级是多少?开户安全吗?我想开户,可以吗?
Simulation volume leetcode [general] 1705 The maximum number of apples to eat
Analysis of abnormal channel number information before and after AGC re signature service
MySQL主从延迟的解决方案
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
OpenGL 3D graphics rendering
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
LeetCode 736. LISP syntax parsing
Markdown编辑器Editor.md插件的使用