我这里主要是针对于登录下cookies使用的封装
在config文件下,新建conf.py和conf.yaml
conf.py内
import os
from utils.YamlUtils import YamlReader
import json
#1. 获取项目的基本目录
#获取当前项目的绝对路径
current_path = os.path.abspath(__file__)
# print(current_path)
#获取当前目录的父级的父级目录(API_autotest)
BASE_DIR = os.path.dirname(os.path.dirname(current_path))
# print (BASE_DIR)
#定义config目录的路径
_config_path = BASE_DIR + os.sep + "config"
#定义config.yml文件的路径
_config_file = _config_path + os.sep + "conf.yml"
def get_config_path():
return _config_path
def get_config_file():
return _config_file
#2. 读取配置文件
class ConfigYaml:
def __init__(self):
'''
初始化yaml读取配置文件
:return:
'''
self.config = YamlReader(get_config_file()).data()
def get_cookies(self):
return self.config["cookies"]
if __name__ == "__main__":
conf_read = ConfigYaml()
co = conf_read.get_cookies()
a=eval(co)
print(a)
print(type(a))
conf.yaml下存放cookies
cookies: '{"domain": "", "httpOnly": True, "name": "GWSSID", "sameSite": "Lax", "path": "/", "Size": 42, "secure": False, "value": ""}'