当前位置: 首页 > news >正文

如果创建网站谷歌海外推广怎么做

如果创建网站,谷歌海外推广怎么做,wordpress怎么添加栏目,免费咨询劳动法电话直接上干货撸代码,有一些是通用的工具类代码,一次性封装永久使用,期待大家的关注,一起加油!!! 配置文件 根据不同的业务需求进行配置,例如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_switch=False):"""获取配置的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", encoding="UTF-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_style=False)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 = None@propertydef 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_epic@propertydef 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_feature@propertydef 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_story@propertydef 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_name@propertydef 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_name@propertydef 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 path@propertydef 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_switch=True)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_feature=self.allure_feature,allure_story=self.allure_story,class_title=self.get_test_class_title,func_title=self.get_func_title,case_path=self.get_case_path,case_ids=self.case_ids,file_name=self.get_file_name)

下一篇介绍用例内容写入/utils/write_testcase_file.py,使用pytest实现自动化

http://www.yayakq.cn/news/602115/

相关文章:

  • 小型企业网站建设旅游景点网论文广州网页设计公司公司
  • 网站广告怎样做工地施工模板尺寸要求
  • 营销类网站 英文seo外包顾问
  • 沂源手机网站建设公司东软 网站群平台建设
  • js网站模板石景山网站开发
  • 辽宁建设工程信息网官网新网站入口买服务器做网站主机
  • 淘宝联盟链接的网站怎么做网站小图标怎么做
  • 婚恋网站 模板建筑类电商网站
  • 做的网站要花钱吗域名怎么获得
  • 南通建公司网站人工智能的关键词
  • 青海专业网站建设推广平台建设在工商局网站怎么做清算
  • index网站制作唐山哪里建筑工地最好
  • 房地产网站策划wordpress指定关键词自动内链
  • 铜仁市网站建设济南网站制作哪家最好
  • 如何查网站备案信息做旅游攻略什么网站最好
  • 沈阳做网站的公司排名设计网免费
  • 泉州企业网站制作做网站需要掌握的技术
  • 无锡做网站公司电话上海网站设计见建设
  • 宝塔网站搭建教程智慧园区建设总体方案
  • 远近互联网站建设分类信息网站程序
  • 苏州智能网站建设策划电子商务网站建设规划书
  • 网站免费建站2软件开发工具属于
  • 新网站不被收录的原因如何进行软件开发
  • 网站建设从零到精通.pdfhtml菜鸟工具
  • 口碑好网站建设报价天津建设发展集团有限公司
  • 自己怎么做直播网站怎样在微信上制作自己的链接
  • wordpress 中文 cms抖音优化排名
  • 淘宝刷单网站开发设计交流网站
  • 查询公司营业执照的网站在线广告平面设计
  • 长沙企业网站制作相亲网站建设