apitest/scripts/writePage.py

47 lines
1.4 KiB
Python

# coding:utf-8
import os
from config.confManage import dir_manage
from scripts.log import Log
from scripts.readYamlFile import ini_yaml
Log()
import logging
def getFilePathList(path, filetype):
pathList = []
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(filetype):
pathList.append(os.path.join(root, file))
return pathList
def write_case(_file):
path = dir_manage(dir_manage('${pro_dir}$') + dir_manage('${test_suite}$') + dir_manage('${page_dir}$'))
with open(path + r"saasApp_pages_1.py", 'w+', encoding='utf-8') as f:
f.write("""# coding:utf-8\nfrom test_suite.page import *\n\nurlData = ini_yaml("urlData.yml")\n\n""")
yml_data = ini_yaml(_file)
for item in yml_data.items():
logging.debug("正在生成page文件.{}".format(str(item)))
f.write("""
def {testtitle}(casedata):""".format(testtitle=item[0]))
f.write("""
data = urlData["{0}"]""".format(item[0])
)
f.write(
"""
logging.info("{}".format(casedata["info"]))
res, restime = apisend(address=data["address"], method=data["method"], headers=casedata["headers"],
data=casedata["data"])
return res, restime\n\n"""
)
if __name__ == '__main__':
ym_path = r'urlData.yml'
write_case(ym_path)