当前位置:网站首页>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 …….

边栏推荐
- [happy Lantern Festival] guessing lantern riddles eating lantern festival full of vitality ~ (with lantern riddle guessing games)
- JVM系列(2)——垃圾回收
- MySQL的开发环境和测试环境有什么区别??
- Explain final, finally, and finalize
- Key summary IV of PMP examination - planning process group (2)
- Stutter participle_ Principle of word breaker
- 标识符的命名规则和规范
- PMP考试重点总结九——收尾
- Crawler small operation
- ==And eqauls()
猜你喜欢

Unity AssetBundle asset packaging and asset loading

Bridge mode

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

解析:去中心化托管解决方案概述

Numpy array: join, flatten, and add dimensions

English translation plug-in installation of idea

Au revoir! Navigateur ie, cette route Edge continue pour IE

File operations in QT

An error is reported when uninstalling Oracle

Instant messaging and BS architecture simulation of TCP practical cases
随机推荐
Data visualization makes correlation analysis easier to use
Dolphin scheduler uses system time
Application of X6 in data stack index management
Crawler small operation
增强 Jupyter Notebook 的功能,这里有四个妙招
flink cep 跳过策略 AfterMatchSkipStrategy.skipPastLastEvent() 匹配过的不再匹配 碧坑指南
Settings of gift giving module and other custom controls in one-to-one video chat system code
Proxy mode (proxy)
HDI blind hole design, have you noticed this detail?
PMP考试重点总结八——监控过程组(2)
Looking at jBPM from jbm3 to jbm5 and activiti
Stutter participle_ Principle of word breaker
PyGame game: "Changsha version" millionaire started, dare you ask? (multiple game source codes attached)
Wechat applet development log
JVM系列(2)——垃圾回收
Bron filter Course Research Report
PMP考试重点总结六——图表整理
Differences between task parameter types inout and ref
Redis sentinel cluster main database failure data recovery ideas # yyds dry goods inventory #
适配器模式(Adapter)