当前位置:网站首页>【Selenium】Yaml数据驱动
【Selenium】Yaml数据驱动
2022-04-22 04:43:00 【殷小速】
1 Yaml介绍安装
1.1 Yaml简介
在自动化测试领域,数据是需要与代码分离的。数据驱动一般分为两类:Excel,Yaml
选择数据驱动类型是基于测试框架来定义的,也是基于企业实际框架的应用来决定的。
1.2 环境搭建
- PyYaml安装:
pip install PyYaml - Pycharm导入:
import yaml - 创建Yaml文件:Yaml是一种置标语言(通过缩进和空格进行管理,能够实现各类数据类型的展示)
2 Yaml数据文件
2.1 Yaml数据格式
import yaml
# 读取文件
file = open('./data/yaml_data.yaml', 'r', encoding='utf-8')
data = yaml.load(stream=file, Loader=yaml.FullLoader)
# 数据类型的展示
print(type(data))
# 数据内容的展示
print(data)
- list集合
-
- 1
- 2
-
- a
- b
- 一
- 二
读取输出结果如下:

- 字典
dict1:
name: jessica
age: 18
sex: 女
dict2:
name: Bob
age: 29
sex: 男
读取输出结果如下:

- 集合+字典
-
name: jessica
age: 18
sex: 女
address:
country: USA
state: Florida
-
name: Bob
age: 29
sex: 男
address:
country: USA
state: New York
读取输出结果如下:

2.2 Yaml使用
unittest可以完美使用ddt中的file_data对yaml数据文件进行解析并调用
import unittest
from ddt import ddt, file_data
@ddt
class YamlDemo(unittest.TestCase):
@file_data('./data/yaml_data.yaml')
def test_01(self, **kwargs):
print(kwargs)
print(kwargs.get('name'))
print(kwargs['age'])
print(kwargs['address']['state'])
if __name__ == '__main__':
unittest.main()
版权声明
本文为[殷小速]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_49026134/article/details/124331371
边栏推荐
猜你喜欢

一文告诉你分析即服务(AaaS)到底是什么

【S32K3_STM&PIT_MCAL】

An article tells you what analysis as a service (AAAS) is

7_ Data analysis - Evaluation

2022T电梯修理考试试题及在线模拟考试

goland汉化解决方法(下载插件失败的情况下)

同行面试分享 联想 winform方向 20220420

2022t elevator repair test exercises and online simulation test

2022a special equipment related management (elevator) test question simulation test question bank simulation test platform operation

2022 P cylinder filling training questions and answers
随机推荐
一文告诉你分析即服务(AaaS)到底是什么
线程池状态+ThreadPoolExecutor
10. Libevent receives and processes server messages
链表第四篇
Convert a matrix into a sparse matrix, and then convert a sparse matrix into a matrix (Part I)
[vi] summary
树莓派4B编译paddlelite(详细步骤2022年)
10.libevent接收和处理服务器消息
解决IDEA中文乱码问题(配置文件乱码)
rsync概述
2022p cylinder filling test question bank and simulation test
2021-08-14
If you want to change your career to take the test, I advise you to understand these contents first
Peer interview sharing Lenovo WinForm direction 20220420
2022T电梯修理考试练习题及在线模拟考试
Article 1 of linked list
Error encountered when installing opencv
[concurrent programming 045] what is pseudo shared memory sequence conflict? How to avoid?
LeetCode 剑指 Offer 18. 删除链表的节点
仿真生成随机数计算生成每个同学生日