dedecms网站地图制作,手表排名哪个网站好,j建设银行查数据的网站,框架网页模板下载直接上干货撸代码#xff0c;有一些是通用的工具类代码#xff0c;一次性封装永久使用#xff0c;期待大家的关注#xff0c;一起加油#xff01;#xff01;#xff01;
配置文件
根据不同的业务需求进行配置#xff0c;例如Goods服务、Order服务分开配置#xff0…直接上干货撸代码有一些是通用的工具类代码一次性封装永久使用期待大家的关注一起加油
配置文件
根据不同的业务需求进行配置例如Goods服务、Order服务分开配置每个服务下配置接口信息每个接口文件里配置各种case。 /conf/GooodsApi/get_shop_info.yaml
# 公共参数
case_common:allureEpic: 商品接口allureFeature: 店铺信息allureStory: 店铺信息get_user_info_01:host: https://goodsapi.e.weibo.comurl: /mp/shop/getShopInfomethod: GETdetail: 获取商家店铺信息headers:
# Content-Type: multipart/form-data;# 这里cookie的值写的是存入缓存的名称
# cookie: $cache{login_cookie}# 请求的数据是 params 还是 json、或者file、datarequestType: params# 是否执行空或者 true 都会执行is_run:data:{shop_id: xxxx}# 是否有依赖业务为空或者false则表示没有dependence_case: False# 依赖的数据dependence_case_data:assert:# 断言接口状态码errorCode:jsonpath: $.codetype: value: 0AssertType:sql:通用工具类
文件操作
/utils/file_operate.py
import osdef get_root_path():获取(项目)根目录return os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def ensure_path_sep(path):兼容windows和Linux不同环境的操作系统路径if / in path:path os.sep.join(path.split(/))if \\ in path:path os.sep.join(path.split(\\))return get_root_path() pathdef get_all_yaml_files(file_path, yaml_data_switchFalse):获取配置的yaml文件路径file_name []for root, dir, files in os.walk(file_path):for _file_path in files:path os.path.join(root, _file_path)if yaml_data_switch:if yaml in path or .yml in path:file_name.append(path)file_name.append(path)return file_name操作yaml
/utils/yaml_control.py
Class YamlControl:def __init__(self, file_str):self.file_str file_strdef file_is_exists(self, filepath):if os.path.exists(filepath):return Truereturn Falsedef read_yaml_data(self):获取yaml文件数据if self.file_is_exists(self.file_str):data open(self.file_str, r, encodingUTF-8)yaml_data yaml.load(data, Loader yaml.FullLoader)else:raise FileNotFoundError(文件路径不存在)return yaml_datadef save_yaml_data(self, file_path, data):if self.file_is_exists(file_path):with open(file_path, w) as file:yaml.safe_dump(data, file, default_flow_styleFalse)else:raise FileNotFoundError(文件路径不存在)自动生成用例代码
/utils/case_automatic_genration.py
import os
from utils.read_file_tools import get_all_yaml_files, ensure_path_sep
from utils.yaml_control import YamlControl
from utils.test_case import write_testcase_fileclass TestCaseAutomaticGeneration:def __init__(self):self.yaml_case_data Noneself.file_path Nonepropertydef allure_epic(self):_allure_epic self.yaml_case_data.get(case_common).get(allureEpic)assert _allure_epic is not None, (用例中 allureEpic 为必填项请检查用例内容, 用例路径%s % self.file_path)return _allure_epicpropertydef allure_feature(self):_allure_feature self.yaml_case_data.get(case_common).get(allureFeature)assert _allure_feature is not None, (用例中 allureFeature 为必填项请检查用例内容, 用例路径%s % self.file_path)return _allure_featurepropertydef allure_story(self):_allure_story self.yaml_case_data.get(case_common).get(allureStory)assert _allure_story is not None, (用例中 allureStory 为必填项请检查用例内容, 用例路径%s % self.file_path)return _allure_storypropertydef case_data_path(self):返回 yaml 用例文件路径return ensure_path_sep(/conf)propertydef gen_file_name(self):生成文件名 将.yaml替换成.py# 例 /get_shop_info.yaml——/get_shop_info.py# 获取配置文件相对路径l len(self.case_data_path)yaml_path self.file_path[l:]file_name Noneif .yaml in yaml_path:file_name yaml_path.replace(.yaml, .py)elif .yml in yaml_path:file_name yaml_path.replace(.yml, .py)return file_namepropertydef get_test_class_title(self):自动生成类名# 例 get_shop_info——GetShopInfo_file_name os.path.split(self.gen_file_name)[1][:-3]_name _file_name.split(_)_name_len len(_name)for i in range(_name_len):_name[i] _name[i].capitalize()_class_name .join(_name)return _class_namepropertydef get_func_title(self):自动生成方法名return os.path.split(self.gen_file_name)[1][:-3]propertydef spilt_path(self):# 使用/分割 获取文件名称path self.gen_file_name.split(os.sep)path[-1] path[-1].replace(path[-1], test_ path[-1])return pathpropertydef get_case_path(self):生成测试用例目录# 相对路径 test_case/x/test_get_shop_info.pyreturn ensure_path_sep(/test_case os.sep.join(self.spilt_path)) propertydef case_ids(self):return [k for k in self.yaml_case_data.keys() if k ! case_common]propertydef get_file_name(self):# 这里通过/ 符号进行分割提取出来文件名称# 判断生成的 testcase 文件名称需要以test_ 开头case_name self.spilt_path[-1].replace(self.spilt_path[-1], test_ self.spilt_path[-1])return case_namedef mk_dir(self) - None: 判断生成自动化代码的文件夹路径是否存在如果不存在则自动创建 # _LibDirPath os.path.split(self.libPagePath(filePath))[0]_case_dir_path os.path.split(self.get_case_path)[0]if not os.path.exists(_case_dir_path):os.makedirs(_case_dir_path)def get_case_automatic(self):自动生成测试用例代码# 获取配置文件下全部yaml文件file_path get_all_yaml_files(ensure_path_sep(/conf), yaml_data_switchTrue)for file in file_path:# 判断代理拦截的yaml文件不生成test_case代码if proxy_data.yaml not in file:# 获取配置yaml用例数据self.yaml_case_data YamlControl(file).read_yaml_data()# yaml文件相对路径self.file_path file# 判断用例需要用的文件夹路径是否存在不存在则创建self.mk_dir()print(self.gen_file_name, \n,self.get_test_class_title,\n,self.get_func_title,\n,self.get_case_path,\n,self.case_ids,\n,self.get_file_name)write_testcase_file(allure_epic self.allure_epic,allure_featureself.allure_feature,allure_storyself.allure_story,class_titleself.get_test_class_title,func_titleself.get_func_title,case_pathself.get_case_path,case_idsself.case_ids,file_nameself.get_file_name)
下一篇介绍用例内容写入/utils/write_testcase_file.py使用pytest实现自动化 文章转载自: http://www.morning.mbmtz.cn.gov.cn.mbmtz.cn http://www.morning.mgtmm.cn.gov.cn.mgtmm.cn http://www.morning.pypbz.cn.gov.cn.pypbz.cn http://www.morning.jppdk.cn.gov.cn.jppdk.cn http://www.morning.rui931.cn.gov.cn.rui931.cn http://www.morning.rfgkf.cn.gov.cn.rfgkf.cn http://www.morning.bqmsm.cn.gov.cn.bqmsm.cn http://www.morning.sltfk.cn.gov.cn.sltfk.cn http://www.morning.hzryl.cn.gov.cn.hzryl.cn http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.tgfsr.cn.gov.cn.tgfsr.cn http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn http://www.morning.kqgsn.cn.gov.cn.kqgsn.cn http://www.morning.jgttx.cn.gov.cn.jgttx.cn http://www.morning.ltffk.cn.gov.cn.ltffk.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.kstgt.cn.gov.cn.kstgt.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn http://www.morning.qfdyt.cn.gov.cn.qfdyt.cn http://www.morning.ccdyc.cn.gov.cn.ccdyc.cn http://www.morning.ppbrq.cn.gov.cn.ppbrq.cn http://www.morning.lxfdh.cn.gov.cn.lxfdh.cn http://www.morning.qrcxh.cn.gov.cn.qrcxh.cn http://www.morning.nsppc.cn.gov.cn.nsppc.cn http://www.morning.jfbbq.cn.gov.cn.jfbbq.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.zljqb.cn.gov.cn.zljqb.cn http://www.morning.kfcz.cn.gov.cn.kfcz.cn http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn http://www.morning.brjq.cn.gov.cn.brjq.cn http://www.morning.gxeqedd.cn.gov.cn.gxeqedd.cn http://www.morning.fbnsx.cn.gov.cn.fbnsx.cn http://www.morning.lonlie.com.gov.cn.lonlie.com http://www.morning.trplf.cn.gov.cn.trplf.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.jnvivi.com.gov.cn.jnvivi.com http://www.morning.brzlp.cn.gov.cn.brzlp.cn http://www.morning.ccdyc.cn.gov.cn.ccdyc.cn http://www.morning.pbdnj.cn.gov.cn.pbdnj.cn http://www.morning.hkysq.cn.gov.cn.hkysq.cn http://www.morning.xnlj.cn.gov.cn.xnlj.cn http://www.morning.flxqm.cn.gov.cn.flxqm.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.byshd.cn.gov.cn.byshd.cn http://www.morning.lblsx.cn.gov.cn.lblsx.cn http://www.morning.zpstm.cn.gov.cn.zpstm.cn http://www.morning.bpmfr.cn.gov.cn.bpmfr.cn http://www.morning.nkkr.cn.gov.cn.nkkr.cn http://www.morning.xhfky.cn.gov.cn.xhfky.cn http://www.morning.trrrm.cn.gov.cn.trrrm.cn http://www.morning.drtgt.cn.gov.cn.drtgt.cn http://www.morning.fxjnn.cn.gov.cn.fxjnn.cn http://www.morning.nmfml.cn.gov.cn.nmfml.cn http://www.morning.dlgjdg.cn.gov.cn.dlgjdg.cn http://www.morning.incmt.com.gov.cn.incmt.com http://www.morning.hsrpc.cn.gov.cn.hsrpc.cn http://www.morning.gryzk.cn.gov.cn.gryzk.cn http://www.morning.kydrb.cn.gov.cn.kydrb.cn http://www.morning.lhztj.cn.gov.cn.lhztj.cn http://www.morning.rqqn.cn.gov.cn.rqqn.cn http://www.morning.tdttz.cn.gov.cn.tdttz.cn http://www.morning.dpbgw.cn.gov.cn.dpbgw.cn http://www.morning.rhsg.cn.gov.cn.rhsg.cn http://www.morning.fmrwl.cn.gov.cn.fmrwl.cn http://www.morning.jxcwn.cn.gov.cn.jxcwn.cn http://www.morning.xhlpn.cn.gov.cn.xhlpn.cn http://www.morning.wxccm.cn.gov.cn.wxccm.cn http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn http://www.morning.xqcbz.cn.gov.cn.xqcbz.cn http://www.morning.tsynj.cn.gov.cn.tsynj.cn http://www.morning.lbpfl.cn.gov.cn.lbpfl.cn http://www.morning.ltpmy.cn.gov.cn.ltpmy.cn http://www.morning.rldph.cn.gov.cn.rldph.cn http://www.morning.wqpm.cn.gov.cn.wqpm.cn http://www.morning.qkskm.cn.gov.cn.qkskm.cn http://www.morning.flchj.cn.gov.cn.flchj.cn http://www.morning.dpbgw.cn.gov.cn.dpbgw.cn http://www.morning.gbkkt.cn.gov.cn.gbkkt.cn http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn http://www.morning.cnkrd.cn.gov.cn.cnkrd.cn