当前位置:网站首页>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 )
边栏推荐
- Mapping location after kotlin confusion
- [C language] Dynamic Planning --- from entry to standing up
- Ruby replaces gem Alibaba image
- C language practice - number guessing game
- [Yu Yue education] autumn 2021 reference materials of Tongji University
- geotrust ov多域名ssl证书一年两千一百元包含几个域名?
- Why can't you remember when reading? Why can't you remember- My technology learning methodology
- Common errors of dmrman offline backup
- Analyze the space occupied by the table according to segments, clusters and pages
- DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
猜你喜欢

Keil compilation code of CY7C68013A

Rhcsa --- work on the third day

Learn BeanShell before you dare to say you know JMeter

记录一次Unity 2020.3.31f1的bug

Alibaba cloud polkit pkexec local rights lifting vulnerability

idea自动导包和自动删包设置

Play with concurrency: draw a thread state transition diagram

Pytorch---使用Pytorch实现U-Net进行语义分割

C language practice - number guessing game

Win10 disk management compressed volume cannot be started
随机推荐
Orthogonal test method and function diagram method for test case design
My first experience of shadowless cloud computer
What are the rules and trading hours of agricultural futures contracts? How much is the handling fee deposit?
The solution to the complexity brought by lambda expression
二叉树解题(一)
Virtual machine installation deepin system
Detailed process of DC-1 range construction and penetration practice (DC range Series)
Starting from the classification of database, I understand the map database
初学爬虫-笔趣阁爬虫
Design and implementation of general interface open platform - (44) log processing of API services
汇编语言中的标志位:CF、PF、AF、ZF、SF、TF、IF、DF、OF
Learn what definitelytyped is through the typescript development environment of SAP ui5
Ruby replaces gem Alibaba image
TypeScript函数详解
Common locks in MySQL
Mapping location after kotlin confusion
Binary tree problem solving (2)
One step implementation of yolox helmet detection (combined with oak intelligent depth camera)
MySQL table insert Chinese change? Solution to the problem of No
社交媒体搜索引擎优化及其重要性