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

边栏推荐
- Read PDF image and identify content
- Adapter mode
- [200 opencv routines] 213 Draw circle
- 一文读懂 12种卷积方法(含1x1卷积、转置卷积和深度可分离卷积等)
- 布隆过滤器 课程研究报告
- 2020-10-27
- 再見!IE瀏覽器,這條路由Edge替IE繼續走下去
- 线程的生命周期
- PHP curl forged IP address and header information code instance - Alibaba cloud
- QT signal and slot communication mechanism (when multiple windows communicate back and forth [parent and child windows])
猜你喜欢

纵观jBPM从jBPM3到jBPM5以及Activiti

函数的分文件编写

I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!

JVM系列(2)——垃圾回收

线程的生命周期

Decorator

Redis sentinel cluster main database failure data recovery ideas # yyds dry goods inventory #

我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!

为什么 Istio 要使用 SPIRE 做身份认证?

Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
随机推荐
在OpenCloudOS使用snap安装.NET 6
Chapter 5 trees and binary trees
File operations in QT
如图 用sql行转列 图一原表,图二希望转换后
Function sub file writing
Instant messaging and BS architecture simulation of TCP practical cases
JSON数据与List集合之间的正确转换
2020-10-27
PMP考试重点总结四——规划过程组(2)
Thread lifecycle
装饰模式(Decorator)
Bron filter Course Research Report
Crawler small operation
PMP Exam key summary IX - closing
Regular verification of mobile phone number and email [easy to understand]
DolphinScheduler使用系统时间
Methods for creating multithreads ---1 creating subclasses of thread class and multithreading principle
Django数据库操作以及问题解决
Dotnet uses crossgen2 to readytorun DLL to improve startup performance
Data visualization makes correlation analysis easier to use