One 、 Preface : It took a while for the interface automation testing framework encapsulated a while ago to find that there are still many drawbacks , At present, it has been improved , It can be said that the whole idea has been overthrown , It is much more powerful than before , If you are interested, please send me a private letter to communicate with you alone , Hope to learn and make progress together !
Two 、 Project directory
case Catalog : Store test execution files
config Catalog : Store the configuration file ( Database connection information 、token Information, etc )、 Temporarily stored files ( You need to extract the fields of the interface to use )
data Catalog : Store test case data files
files Catalog : Store accessories ( The upload interface requires )
log Catalog : Store the generated log file
logs Catalog : Encapsulated logs
report Catalog : Deposit allure Test report
utils Catalog : Secondary packaging requests、 Database connection 、 Assertion 、 General methods, etc
conftest.py: Method to perform initialization , This is mainly when the test case collection is completed , What will be collected item Of name and nodeid The Chinese language of is displayed on the console
main.py: The main entry of the program
pytest.ini: To configure pytest Test the rules executed by the framework
readme.md: Some descriptions of interface automation test framework
requestsirements.txt: Some third-party libraries that need to be installed
3、 ... and 、 The core idea ( Use a specific example to illustrate ):
First, execute case Test cases in the directory py file , Then read the corresponding data Test cases maintained under , And then call utils Lower encapsulated requestUtil class , Execute check_case().requestUtil Under the package request、 assert methods . See the screenshot code for details . The general idea is like this , Please study by yourself .
For special reasons , Some screenshots are incomplete , You can use your ideas for reference , No need to copy .