yaml读取封装
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
对yaml格式的配置文件的操作
""" import yaml
import env
from vendor.config.config_handle import ConfigHandle class YamlHandle(ConfigHandle):
def __init__(self, dir_name, file_name): # 知识点
"""
@param dir_name: 文件夹名字,从env.py文件导入,eg:env.ELEMENTINI_PATH
@param file_name: 文件名字
"""
print(file_name)
try:
self.f = open(super().get_file_full_path_name(dir_name, file_name), 'r', encoding='utf-8')
self.cfg = self.f.read()
except:
print("配置文件不存在") """
获取yaml文件中的字典value值,可获取字典值任意一层
ele_dict = {
'password_input':
{
'dec': '登录按钮',
'type': 'XPATH',
'value': '//button'
},
'account_number_input':
{
'dec': '账号输入框',
'type': 'CLASS_NAME',
'value': 'ivu-input',
'index': 0
},
}
"""
def get_value(self, *keys):
"""
@param keys:yaml文件中的key值,可多层,['password_input','dec']或者['password_input']
@return: 返回字典中value值
"""
try:
ele_dict = yaml.load(self.cfg, Loader=yaml.FullLoader) # 用load方法转字典
print(ele_dict)
if not keys:
return ele_dict
else:
for key in keys:
tmp = ele_dict.get(key)
if tmp is not None:
ele_dict = tmp
return ele_dict
except:
print("值不存在") def __del__(self):
try:
self.f.close()
except:
print("文件操作符关闭失败") if __name__ == '__main__':
yh = YamlHandle(env.ELEMENTINI_PATH, 'admin_login.yaml')
print(yh.get_value('login_button'))
yaml读取封装的更多相关文章
- python接口自动化读取json,yaml配置文件+封装requests+unittest+HTMLRunner实现全自动化
# coding=utf-8 import json import requests class TestApi(object): """ /* @param: @ses ...
- SpringBoot源码学习系列之@PropertySource不支持yaml读取原因
然后,为什么@PropertySource注解默认不支持?可以简单跟一下源码 @PropertySource源码: 根据注释,默认使用DefaultPropertySourceFactory类作为资源 ...
- ADO.NET数据读取封装
public class sqlserver { //private string sqlstr = System.ConfigurationManager.ConnectionStrings[&qu ...
- bladex从blade-dev.yaml 读取配置信息
blade-dev.yaml配置======nacos文件配置 #sap配置 sap: api: read: url: http://read.xxxxxxxx.com.cn port: 80 use ...
- execl文件读取封装
前言:做自动化常用的公共方法 注:第一次使用记得先 pip install xlrd 模块import xlrd class ReadExecl(): def __init__(self,filena ...
- SpringBoot系列之@PropertySource读取yaml文件
SpringBoot系列之@PropertySource支持yaml文件读取 最近在做实验,想通过@PropertySource注解读取配置文件的属性,进行映射,习惯上用properties都是测试没 ...
- python之读取yaml数据
一.yaml简介 yaml:一种标记语言,专门用来写配置文件. 二.yaml基础语法 区分大小写: 使用缩进表示层级关系: 使用空格键缩进,而非Tab键缩进 缩进的空格数目不固定,只需要相同层级的元素 ...
- 一篇文章告诉你Python接口自动化测试中读取Text,Excel,Yaml文件的方法
前言 不管是做Ui自动化和接口自动,代码和数据要分离,会用到Text,Excel,Yaml.今天讲讲如何读取文件数据 Python也可以读取ini文件,传送门 记住一点:测试的数据是不能写死在代码里面 ...
- python接口自动化测试二十九:yaml配置文件的写和读
# 先安装ruamel.yaml模块 写入配置文件: import os# 先安装ruamel.yaml模块from ruamel import yaml # 将字典写入到yamldict = { ' ...
随机推荐
- wordpress评论回复邮件通知功能
安装插件登录后台——点击“插件”——“安装插件”——按关键字搜索“Comment Reply Notification”——点击“现在安装”安装好后启用插件.如下图所示: 配置Comment Repl ...
- 自定义reaml创建使用实现认证
注意清空shiro.ini 创建User对象 package cn.zys.Bean; public class User { private Integer id; private String u ...
- Oracle 中同义词使用
一.数据库对象: 模式对象: 数据库对象是逻辑结构的集合,最基本的数据库对象是表; 其他对象包括:create增.drop删.改alter 同义词.序列.视图.索引 1.同义词: ①. 现有对象的一个 ...
- linux 权限笔记
权限模型 linux权限模型,指的是对文件.文件夹同的读写权限,同用户之间的权限管理模型 三种角色 user 文件.文件夹的创建者,所有人 group 一个group对应多个user,user自动具有 ...
- 前端基础进阶(十四):es6常用基础合集
在实际开发中,ES6已经非常普及了.掌握ES6的知识变成了一种必须.尽管我们在使用时仍然需要经过babel编译. ES6彻底改变了前端的编码风格,可以说对于前端的影响非常巨大.值得高兴的是,如果你熟悉 ...
- [PHP自动化-进阶]004.Snoopy VS CURL 模拟Discuz.net登陆
引言:采集论坛第一步就是要模拟登陆,由于各个站点登录表单各不相同,验证方式又是多种多样,所以直接提交用户名密码到登录页面就比较繁琐. 所以我们采用cookie来模拟登陆无疑是最佳捷径. 今天我们要处理 ...
- Unable to start services. See log file /tmp/vmware-root/vmware-6853.log for details.
debian安装vmware错误 https://github.com/AdministratorGithub/vmshell vm15.1.0解决linux安装出现Unable to start s ...
- Python之TestLink篇
如何让时间变慢? 你们不知道吧,这个时候翻开书,时间又变慢了一倍,可以这样延年益寿,哈哈哈 ------------------------------------------------------ ...
- jupyter notebook 安装扩展nbextensions
安装nbextensions可提高jupyter notebook效率,安装步骤如下: 1.pip 方式安装: (gluon) [root@localhost ~]# pip install jupy ...
- 跨域解决方案 - JSONP
目录 1. 定义 2. JSONP 解决跨域 3. 应用场景 4. 代码演示 1. 定义 在HTML 中, script 标签有两个个性质: script 标签可以不受同源策略的限制去访问服务器资源, ...