当前位置:网站首页>The boss asked me to write an app automation -- yaml file reading -- with the whole framework source code attached
The boss asked me to write an app automation -- yaml file reading -- with the whole framework source code attached
2022-06-28 10:00:00 【Little brother said test】
Preface
Here is the little brother said test , I stopped for a long time , Mainly in the automation framework , These are the things described in this article . The frame is finished , The rest is to slowly decompose , In the form of an article .
readyaml
This chapter is still about what was not covered in the previous chapter . Read yaml file . We are based on yaml Files as the basis for automated use cases . So it is necessary to read it . Even if it's excel It's the same .
Look at the code
# encoding=utf-8
# ---- Qing'an —---
# WeChat :qing_an_an
# official account : Measured number der
import yaml
class YamlRead:
def __init__(self, yamlPath):
''' If it's the first call , Read yaml file , Otherwise, the previously saved data will be returned directly '''
if os.path.exists(yamlPath):
self.yamlPath = yamlPath
else:
raise FileNotFoundError('yaml file does not exist ')
self._data = None # preservation yaml The data of
@property # Change a method into a property to call ,
def getData(self):
if not self._data:
with open(self.yamlPath, mode='rb') as f:
self._data = yaml.load(f, Loader=yaml.FullLoader)
return self._data
There are some notes here , A simple understanding is that a yaml File path , Made a series of judgments , Finally, get the contents , And return the result value . Other codes are used to verify such an operation , Dealing with exceptions .
Here, you don't need to call for the next call (), So here we add a decorator , take getData Call... As a property . If you don't understand or don't understand , You can look at the front python article .
How to use
In combination with what was said in the previous section configs class , stay case Write a yaml file . Code up :
# encoding=utf-8
# ---- Qing'an —---
# WeChat :qing_an_an
# official account : Measured number der
import os
class Config:
''' The relative path of all files under the project '''
Base_Path = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + '/..')
Base_yaml = Base_Path + r'\case\login.yaml'
re = Config()
Then call the printer to see , Path splicing has OK 了 . So is this omnipotent ? The answer is , No, it isn't . This is just to facilitate the management of some files , It's not a panacea .
Finish here , We then went directly to the YamlRead Call it in
from configs.readconfig import re
r = YamlRead(re.Base_YAML).getData
print(r)
I omitted the code in the above example , Duplication is too much trouble , The following results can be obtained by printing after calling :
[{'mode': 'time', 'time': 5}, {'until': 'presence_located', 'mode': 'inputs_', 'loc': 'id', 'ele': 'com.mxchip.project352:id/etPhone', 'value': '123456', 'time': 10}, {'until': 'presence_located', 'mode': 'inputs_', 'loc': 'class name', 'ele': 'android.widget.EditText', 'value': 'jx123456', 'num': 1}, {'until': 'visibility_located', 'mode': 'clicks_', 'loc': 'id', 'ele': 'com.mxchip.project352:id/cbAgree'}, {'mode': 'time', 'time': 5}, {'until': 'text_element', 'mode': 'clicks_', 'loc': 'xpath', 'text': ' Sign in ', 'ele': '//*[@text=" deng "]'}]
Last , Post my yaml File format comes out :

summary
If you read it successfully , The result is consistent with me , So congratulations , The contents of this chapter have been successfully learned .
Learning resource sharing
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it

These materials , For those who want to advance 【 automated testing 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful …….

边栏推荐
- JSON数据与List集合之间的正确转换
- Key summary V of PMP examination - execution process group
- 如图 用sql行转列 图一原表,图二希望转换后
- English translation plug-in installation of idea
- 线程的生命周期
- Stutter participle_ Principle of word breaker
- Dolphin scheduler uses system time
- ECS MySQL query is slow
- 【OpenCV 例程200篇】213. 绘制圆形
- File operations in QT
猜你喜欢
![[200 opencv routines] 213 Draw circle](/img/8d/a771ea7008f84ae3a3cf41507448ec.png)
[200 opencv routines] 213 Draw circle

适配器模式(Adapter)

Data visualization makes correlation analysis easier to use

How to distinguish and define DQL, DML, DDL and DCL in SQL

错过金三银四,找工作4个月,面试15家,终于拿到3个offer,定级P7+

DolphinScheduler使用系统时间

An error is reported when uninstalling Oracle

Xiaomi's payment company was fined 120000 yuan, involving the illegal opening of payment accounts, etc.: Lei Jun is the legal representative, and the products include MIUI wallet app

解决表单action属性传参时值为null的问题

【NLP】今年高考英语AI得分134,复旦武大校友这项研究有点意思
随机推荐
线程的生命周期
如图 用sql行转列 图一原表,图二希望转换后
Adapter mode
我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
Caffeine cache, the king of cache, has stronger performance than guava
手机号、邮箱正则验证[通俗易懂]
PyGame game: "Changsha version" millionaire started, dare you ask? (multiple game source codes attached)
Dolphin scheduler uses system time
栈的弹出压入序列<难度系数>
手把手教你处理 JS 逆向之 SVG 映射
用 Compose 实现个空调,为你的夏日带去清凉
MySQL的开发环境和测试环境有什么区别??
PHP curl forged IP address and header information code instance - Alibaba cloud
2020-10-27
DolphinScheduler使用系统时间
How to distinguish and define DQL, DML, DDL and DCL in SQL
Comprehensive evaluation of outline note taking software workflow: advantages, disadvantages and evaluation
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
flink cep 跳过策略 AfterMatchSkipStrategy.skipPastLastEvent() 匹配过的不再匹配 碧坑指南
接口自动化框架脚手架-参数化工具的实现