接上篇:
手把手教你学会接口自动化系列八-将url写在配置文件中,封装调用-CSDN博客
下来把之前写的demo开始改造,将所有的url = http://192.168.0.134:8081的部分,替代了
如下:
demo的改造
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/05
# @Author : Liujingjing
import requests
from config.setting import ConfigHandler
from tools.yamlControl import GetYamlData
baseUrl = GetYamlData(ConfigHandler.config_path).get_yaml_data()
url = baseUrl['host']+"/login"
headers={"Content-Type":"application/x-www-form-urlencoded"}
data={"username":"admin","password":"123456"}
response = requests.post(url=url,
headers=headers,
data=data)
print(response.text)
demo2的改造
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/05
# @Author : Liujingjing
# !/usr/bin/