forked from DxvLwRYF/apiAutoTest
优化allure步骤,及部分代码
This commit is contained in:
parent
2f97664f84
commit
c8161ea594
|
@ -9,9 +9,8 @@
|
|||
"""
|
||||
|
||||
import requests
|
||||
from tools import allure_step, allure_title, logger, extractor
|
||||
from tools import allure_step, allure_title, logger, allure_step_no
|
||||
from tools.data_process import DataProcess
|
||||
from tools.read_file import ReadFile
|
||||
|
||||
|
||||
class BaseRequest(object):
|
||||
|
@ -19,6 +18,10 @@ class BaseRequest(object):
|
|||
|
||||
@classmethod
|
||||
def get_session(cls):
|
||||
"""
|
||||
单例模式保证测试过程中使用的都是一个session对象
|
||||
:return:
|
||||
"""
|
||||
if cls.session is None:
|
||||
cls.session = requests.Session()
|
||||
return cls.session
|
||||
|
@ -36,24 +39,18 @@ class BaseRequest(object):
|
|||
# allure报告 用例标题
|
||||
allure_title(case_title)
|
||||
# 处理url、header、data、file、的前置方法
|
||||
url = ReadFile.read_config(
|
||||
f'$.server.{env}') + DataProcess.handle_path(path)
|
||||
allure_step('请求地址', url)
|
||||
url = DataProcess.handle_path(path, env)
|
||||
header = DataProcess.handle_header(header)
|
||||
allure_step('请求头', header)
|
||||
data = DataProcess.handle_data(data)
|
||||
allure_step('请求参数', data)
|
||||
allure_step('请求数据', data)
|
||||
file = DataProcess.handler_files(file_obj)
|
||||
allure_step('上传文件', file_obj)
|
||||
# 发送请求
|
||||
res = cls.send_api(url, method, parametric_key, header, data, file)
|
||||
allure_step('响应耗时(s)', res.elapsed.total_seconds())
|
||||
allure_step('响应内容', res.json())
|
||||
response = cls.send_api(url, method, parametric_key, header, data, file)
|
||||
|
||||
# 保存用例的实际响应
|
||||
if is_save == "是":
|
||||
DataProcess.save_response(case_number, res.json())
|
||||
allure_step('存储实际响应', DataProcess.response_dict)
|
||||
return res.json(), expect, sql
|
||||
DataProcess.save_response(case_number, response)
|
||||
return response, expect, sql
|
||||
|
||||
@classmethod
|
||||
def send_api(
|
||||
|
@ -63,7 +60,7 @@ class BaseRequest(object):
|
|||
parametric_key,
|
||||
header=None,
|
||||
data=None,
|
||||
file=None) -> object:
|
||||
file=None) -> dict:
|
||||
"""
|
||||
:param method: 请求方法
|
||||
:param url: 请求url
|
||||
|
@ -99,6 +96,9 @@ class BaseRequest(object):
|
|||
else:
|
||||
raise ValueError(
|
||||
'可选关键字为params, json, data')
|
||||
response = res.json()
|
||||
logger.info(
|
||||
f'\n最终请求地址:{res.url}\n请求方法:{method}\n请求头:{header}\n请求参数:{data}\n上传文件:{file}\n响应数据:{res.json()}')
|
||||
return res
|
||||
f'\n最终请求地址:{res.url}\n请求方法:{method}\n请求头:{header}\n请求参数:{data}\n上传文件:{file}\n响应数据:{response}')
|
||||
allure_step_no(f'响应耗时(s): {res.elapsed.total_seconds()}')
|
||||
allure_step('响应结果', response)
|
||||
return response
|
||||
|
|
|
@ -36,7 +36,7 @@ database:
|
|||
user: root
|
||||
# 不用''会被解析成int类型数据
|
||||
password: '123456'
|
||||
db_name: test
|
||||
db_name: apiautotest
|
||||
charset: utf8mb4
|
||||
|
||||
# 数据库所在的服务器配置
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue