from locust import TaskSet, task, User,HttpUser
import subprocess
import scmlogin as lg
# from locust import events 事件
#
# @events.test_start.add_listener
# def on_test_start(**kw):
# print("test is starting")
#
# @events.test_stop.add_listener
# def on_test_start(**kw):
# print("test is stopping")
class MyTasks(TaskSet):
"""
创建测试任务类,需要继承TaskSet
可以添加多个测试任务
"""
# 每个测试任务,往往会以实例方法的形式来呈现
# 同时需要使用task装饰器来装饰测试任务
@task
def one_task(self):
param = {'no': 1, 'sku': 'qd', 'startSn': 1, 'endSn': 1000, "prefix": "66666"}
reponse=self.client.post(url="",data=param,cookies=lg.cookie)
print(reponse.status_code)
# print(reponse.json())
# print("测试任务1")
@task
def two_task(self):
param2={'sku': 'nk', 'rfids': '000000000000476898000307,201607000000000000010827,201607000000000000010797','isReplace': 'true'}
reponse=self.client.post(url="",data=param2,cookies=lg.cookie)
print(reponse.status_code)
@task
def three_task(self):
param3={'sku': 'qd2', 'prefix': 'qd2', 'startSn': 1, 'endSn': 8}
reponse=self.client.post(url="",data=param3,cookies=lg.cookie)
print(reponse.status_code)
@task
def four_task(self):
param4={'no': 3, 'skuRfidJson': '[{"sku": "nk","rfids":["0005399001480039","0005399001480040","0005392001540005"]},{"sku": "qd","rfids":["0005392001540006","0005392001540007"]}]'}
reponse=self.client.post(url="",data=param4,cookies=lg.cookie)
print(reponse.status_code)
@task
def five_task(self):
param5={'no': 4, 'sku': 'qd', 'uniqueCodeJsonStr': "[{uniqueCode:'00js22',sdys:1}]"}
reponse=self.client.post(url="",data=param5,cookies=lg.cookie)
print(reponse.status_code)
# class RunTasks(User):
# """
# 创建运行测试类,需要继承Locust父类
# """
# tasks = [MyTasks] # 指定测试任务类,使用task_set覆盖父类的类属性
# min_wait = 2000 # 指定启动任务间隔的时间范围(单位毫秒):2~5秒之间
# max_wait = 5000
class MobileUserLocust(HttpUser):
u"""
min_wait :用户执行任务之间等待时间的下界,单位:毫秒。
max_wait :用户执行任务之间等待时间的上界,单位:毫秒。
"""
# weight = 3
tasks = [MyTasks]
host = "http://localhost:8888" #(待测试的ip或者域名)
min_wait = 2000
max_wait = 5000
if __name__ == "__main__":
subprocess.Popen("locust -f locustfile2.py", shell=True)
locust 测试用例
最新推荐文章于 2022-06-08 08:00:09 发布