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

边栏推荐
- go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
- selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
- 5A summary: seven stages of PMP learning
- Leetcode question brushing record (array) combination sum, combination sum II
- 年薪50w阿里P8亲自下场,教你如何从测试进阶
- Redis fault handling "can't save in background: fork: cannot allocate memory“
- C语言指针(习题篇)
- 【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
- 2021 year end summary
- 如何统计项目代码行数
猜你喜欢

Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
![[istio introduction, architecture, components]](/img/2b/f84e5cdac6ed9b429e053ffc8dbeb0.png)
[istio introduction, architecture, components]

【Istio Network CRD VirtualService、Envoyfilter】

STM32的时钟系统

Summary of PMP learning materials

面板显示技术:LCD与OLED

Several stages of PMP preparation study

PMP examination experience sharing

Systick滴答定时器

External interrupt to realize key experiment
随机推荐
Markdown editor Use of MD plug-in
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
C语言指针(下篇)
The essence of high availability
年薪50w阿裏P8親自下場,教你如何從測試進階
Newly found yii2 excel processing plug-in
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
【istio简介、架构、组件】
Common operating commands of Linux
Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)
Cmake command line use
串口实验——简单数据收发
Interview question: general layout and wiring principles of high-speed PCB
C语言指针(中篇)
What are the suggestions for PMP candidates?
面板显示技术:LCD与OLED
2022-06-30 Unity核心8——模型导入
GoLand set goproxy
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
cmake命令行使用