当前位置:网站首页>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}')

边栏推荐
- Expérience de port série - simple réception et réception de données
- Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
- 模拟卷Leetcode【普通】1706. 球会落何处
- Skills that testers must know: Selenium's three waiting ways are interpreted clearly
- Systick滴答定时器
- 2022-07-06 Unity核心9——3D动画
- PMP Exam Preparation experience systematically improve project management knowledge through learning
- LeetCode 736. Lisp 语法解析
- [chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
- 面试题:高速PCB一般布局、布线原则
猜你喜欢

Mountaineering team (DFS)

PMP certificate preparation experience sharing

Output all composite numbers between 6 and 1000

Register address name mapping

STM32 clock system

硬核分享:硬件工程师常用工具包

JVM garbage collection detailed learning notes (II)

Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions

Markdown editor Use of MD plug-in

使用Typora编辑markdown上传CSDN时图片大小调整麻烦问题
随机推荐
数据在内存中的存储
Serial port experiment - simple data sending and receiving
Systick滴答定时器
Ppt template and material download website (pure dry goods, recommended Collection)
PMP experience learning and sharing process
JVM 内存结构 详细学习笔记(一)
Unity Shader入门精要初级篇(一)-- 基础光照笔记
Summary of PMP learning materials
JVM garbage collection detailed learning notes (II)
Common operating commands of Linux
Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
systemd
模拟卷Leetcode【普通】1567. 乘积为正数的最长子数组长度
[chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
Mountaineering team (DFS)
Simple use of Xray
Calf problem
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
Count the number of words in the string c language
PPT模板、素材下载网站(纯干货,建议收藏)