当前位置:网站首页>Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
2022-07-02 04:42:00 【Peng Yuyan in the testing industry】
In general , We're going through one yaml File association implementation
Create a new file in the root directory yaml, Through the above conftest.py File to update global variables :
1. First, you need to create a read 、 write in 、 eliminate yaml File tool class
as follows :
import os
import yaml
class YamlUnit:
def readAllYaml(self):
with open(os.getcwd() + "/extract.yml", mode='r', encoding='utf-8') as f:
value = yaml.load(stream=f, Loader=yaml.FullLoader)
return value
def readKeyYaml(self,key):
with open(os.getcwd() + "/extract.yml", mode='r', encoding='utf-8') as f:
value = yaml.load(stream=f, Loader=yaml.FullLoader)
return value[key]
def writeYaml(self, data):
with open(os.getcwd() + "/extract.yml", mode='w', encoding='utf-8') as f:
print(os.getcwd() + "/extract.yml")
value = yaml.dump(data=data, stream=f, allow_unicode=True)
def deleteYaml(self):
with open(os.getcwd()+"/extract.yml",mode="w",encoding='utf-8') as f:
f.truncate()
2. coordination conftest.py file + fixture Implement global shared calls
# Realize partial pre
import pytest
from comment.yaml_unit import YamlUnit
@pytest.fixture(scope="function")
def conn_getbase():
print(" Successfully connected to database ")
yield
print(" Closing database succeeded ")
@pytest.fixture(scope="session", autouse=True)
def clear_yaml():
YamlUnit().deleteYaml()
@pytest.fixture(scope="session", autouse=True)
def get_token():
token = ''; # obtain token Code request for
return token
3. When calling, just pass in the method function name
Such as : Before using the following functions, you need to connect to the database , Just incoming conftest.py In the document conn_getbase The function name is just
def test_Login(self,conn_getbase):
# post request
url = "xxxxxxx"
# Parameters
data = {
"captcha": "[email protected]#2019",
"checkKey": 1637811815838,
"password": "123456",
"remember_me": 1,
"username": "admin"
}
rep = requests.request('post', url, json=data)
statues = rep.json()["success"]
message = rep.json()["message"]
if statues:
print(message )
else:
raise Exception(message) The following is the supporting information , For doing 【 software test 】 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 !
Last : It can be in the official account : Programmer Xiaohao ! Get a free copy of 216 Page software testing engineer interview guide document information . And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One button, three links ! Friends who like software testing , You can join our testing technology exchange group :779450660 There are various software testing resources and technical discussions )
边栏推荐
- Yolov5 network modification tutorial (modify the backbone to efficientnet, mobilenet3, regnet, etc.)
- Exposure X8 Standard Version picture post filter PS, LR and other software plug-ins
- Pytoch --- use pytoch to realize u-net semantic segmentation
- Common errors of dmrman offline backup
- Deep understanding of lambda expressions
- office_ Delete the last page of word (the seemingly blank page)
- Playing with concurrency: what are the ways of communication between threads?
- win10 磁盘管理 压缩卷 无法启动问题
- Online incremental migration of DM database
- Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
猜你喜欢
![Introduction to Luogu 3 [circular structure] problem list solution](/img/fd/c0c5687c7e6e74bd5c911b27c3e19c.png)
Introduction to Luogu 3 [circular structure] problem list solution

Research on the security of ognl and El expressions and memory horse

Typescript function details

idea自動導包和自動删包設置

Record the bug of unity 2020.3.31f1 once

Playing with concurrency: what are the ways of communication between threads?

Pytorch---使用Pytorch进行图像定位

记录一次Unity 2020.3.31f1的bug

How much can a job hopping increase? Today, I saw the ceiling of job hopping.

正大美欧4的主账户关注什么数据?
随机推荐
Exposure X8 Standard Version picture post filter PS, LR and other software plug-ins
Rhcsa --- work on the third day
Why can't you remember when reading? Why can't you remember- My technology learning methodology
Beginner crawler - biqu Pavilion crawler
My first experience of shadowless cloud computer
【ClickHouse】How to create index for Map Type Column or one key of it?
C - derived classes and constructors
Exposure X8标准版图片后期滤镜PS、LR等软件的插件
Spring moves are coming. Watch the gods fight
汇编语言中的标志位:CF、PF、AF、ZF、SF、TF、IF、DF、OF
第十六周作业
[C language] Dynamic Planning --- from entry to standing up
Play with concurrency: what's the use of interruptedexception?
How do I interview for a successful software testing position? If you want to get a high salary, you must see the offer
二叉樹解題(二)
Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
Shenzhen will speed up the cultivation of ecology to build a global "Hongmeng Oula city", with a maximum subsidy of 10million yuan for excellent projects
geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
MySQL table insert Chinese change? Solution to the problem of No
How to recover deleted data in disk