preLogin请求
login请求
员工列表查询请求
获取员工信息的请求
更新员工信息的请求
将请求导出为har文件
全局关联设置的字典列表
# 所有需要提取数据的接口都配进来,这里只配了两个。
CORRELATION_DICT_LIST = [
{
"url": "https://tes.yangzc.cn/xlc-ops-b/entryUser/getUserPage",
"params": [{"name": "data.0.id", "value": None, "extract": "userId"}]
},
{
"url": "https://tes.yangzc.cn/xlc-ops-b/preLogin",
"params": [{"name": "data.1.companyId", "value": None, "extract": "companyId"}]
},
]
自定义的字典列表
# har文件里面涉及的需要提取数据的接口使用my_dict_list进行存储
my_dict_list = []
自定义数据提取函数
def _make_extract(self, teststep_dict, entry_json):
"""
:param teststep_dict:
:param entry_json:
:return:
"""
url = entry_json["request"].get("url")
resp_content_dict = entry_json["response"].get("content")
text = resp_content_dict.get("text")
if not text:
return
resp_content_json = json.loads(text)
for my_dict in CORRELATION_DICT_LIST:
if my_dict["url"] == url:
my_dict_list.append(my_dict)
for param in my_dict["params"]:
teststep_dict["extract"].append({param["extract"]: "content." + param["name"]})
str_arr = param["name"].split(".")
try:
param["value"] = resp_content_json[str_arr[0]][int(str_arr[1])][str_arr[2]]
except:
print("出现异常111111111")
break
请求数据函数
def _make_request_data(self, teststep_dict, entry_json):
""" parse HAR entry request data, and make teststep request data
Args:
entry_json (dict):
{
"request": {
"method": "POST",
"postData": {
"mimeType": "application/x-www-form-urlencoded; charset=utf-8",
"params": [
{"name": "a", "value": 1},
{"name": "b", "value": "2"}
}
},
},
"response": {...}
}
Returns:
{
"request": {
"method": "POST",
"data": {"v": "1", "w": "2"}
}
}
"""
method = entry_json["request"].get("method")
if method in ["POST", "PUT", "PATCH"]:
postData = entry_json["request"].get("postData", {})
mimeType = postData.get("mimeType")
# Note that text and params fields are mutually exclusive.
if "text" in postData:
post_data = postData.get("text")
else:
params = postData.get("params", [])
post_data = utils.convert_list_to_dict(params)
request_data_key = "data"
if not mimeType:
pass
elif mimeType.startswith("application/json"):
try:
for my_dict in my_dict_list:
for param in my_dict["params"]:
if param["value"] and param["value"] in post_data:
post_data = post_data.replace(param["value"], "$" + param["extract"])
post_data = json.loads(post_data)
request_data_key = "json"
except JSONDecodeError:
pass
except:
print("出现异常333333333333")
elif mimeType.startswith("application/x-www-form-urlencoded"):
post_data = utils.convert_x_www_form_urlencoded_to_dict(post_data)
try:
for key in post_data:
for my_dict in CORRELATION_DICT_LIST:
for param in my_dict["params"]:
if param["value"] and post_data[key] == param["value"]:
post_data[key] = "$" + param["extract"]
except:
print("出现异常22222222")
else:
# TODO: make compatible with more mimeType
pass
teststep_dict["request"][request_data_key] = post_data
说明:对_make_request_data进行了修改
使用har2case进行转换
检查用例文件里面的测试步骤
使用httprunner回放请求
测试报告
参考资料
[01] httprunner学习2-har2case录制生成脚本
微信扫一扫关注公众号
点击链接加入群聊
https://jq.qq.com/?_wv=1027&k=5eVEhfN
软件测试学习交流QQ群号:511619105
来源:CSDN
作者:勇敢的兵
链接:https://blog.csdn.net/qq_37251897/article/details/104510885