current position:Home>Python based interface automation test project, complete actual project, with source code sharing
Python based interface automation test project, complete actual project, with source code sharing
2022-01-31 10:48:35 【Program yuanxia】
One 、 Preface
This is a base python Interface automation test project , Use excel Manage test cases , Client operation , You don't need to pay attention to the code in the process of use . The design mainly follows two principles : Simple and easy to use 、 Cover common scenes .
Two 、 The basic structure
Project contains 3 Parts of , The configuration file 、 Use case files 、 client .
3、 ... and 、 The page display
1、 The configuration file
2、 Use case files The use case file is excel Format , Two formats of excel, But not recommended .xlsx Format , Because the program deals with .xlsx The format is openpyxl library , Poor performance . Simple and intuitive , Contains interface information , Fields to be verified , Query whether the data is warehoused ( use sql Statements for ), Fixed value , Check whether the data is stored in the warehouse , Response content , Response head , Status code , Data initialization , Data recovery and so on
part101part301 Is the data that needs to be verified section101section301 It's the expected result This part is divided into 3 There are two different verification methods : Part101~section101: Fixed value verification Part101 Fill in JSONPATH Such as ['sites'][0]['name'] Section101 Fill in a fixed expected result, such as :helloworld
Part201~section201: Database verification Part201 It's also JSONPATH, Such as ['sites'][0]['name'] Section201 At this time, a fixed value is no longer filled in , But the data queried from the database , It can be written like this :select 'helloworld' When you need attention , If you need to write in the use case sql sentence ( Not just here ), Then you need to select the database first
Part301~section301: Check whether the data is stored in the warehouse Sometimes this part of verification can be used to verify whether the data is actually stored after the interface request Part301 Fill in sql sentence Section301 Fill in the expected results
JSON analysis : If the interface response level is deep , have access to “JSON analysis ” The function parses the interface response into key-value form , Then directly copy what you want to use jsonpath that will do .
above part101~section301 Part is accurate verification
Fuzzy check : If you don't want to carry out accurate verification , Just want to see if some values are included in the interface response or response header , You can use the response assertion resText or resHeader.
expression : The above verification can usually meet most scenarios , But some scenes can't be well satisfied , Such as , I might want to check the length of a list in the response , Or whether a field is a mobile phone number , At this time, you need to use an expression to verify , The expression here is actually a sentence python Code , If I want to check the length of the list in the interface response, I can write this :len(r.json()['sites'])==3, Note here : The interface response object in the program is “r”.
Database initialization 、 Data recovery 、 Dynamic parameters : These three parts are sql sentence seeing the name of a thing one thinks of its function , Data initialization is the initialization of the database before the interface request , Data recovery refers to the recovery operation of the database after the interface request . Dynamic parameters were originally based on this consideration , The request parameters of some interfaces are not fixed , Then we need to get from the database in real time , If the parameter ID Since the increase , We query the latest information from the database in real time ID Assign to parameter list , It can be written like this :select ID from XX where XX, Using this query in the parameter list ID It needs to be written like this :{“ID”:”${ dyparam001 }”}, Of course, dynamic parameters are not only used for self increasing parameters , Any data extracted from the database can be used as dynamic parameters , If you use sql Random a mobile phone number or call md5 Function to encrypt a value .
${ Variable name },
This is the reference format of variables in this project , There is... In the project 3 Two variables , User variables , Dynamic parameters and interface variables , All use the same reference format .
User variables : User variables are set in the configuration file , Use as a global variable .
Interface variables : In many cases, there will be dependencies between interfaces , For example, other interfaces depend on the login interface , At this time, you need to set the interface variable . Such as B Interface dependency A One of the interfaces [‘token’] Field , Can be in A Interface key001 Fill in [‘token’] stay value001 Fill in token,key001 Is a dependent field ,value001 Is the variable name set for this field , stay B You can use... In the interface ${token} To call this variable .
Header Manager : The header manager can be implicitly called by subsequent interfaces , Or to AB Two interfaces, for example , If B The request header is required for interface request , Of course, it can be in B Of header Fill in , But if B Interface after CDEF…… All need to use the same request header , Then you can use the header Manager , Can be in A Fill in the header manager of {“token”:”${token}”}, If B The... Is not filled in header, that B Will be quoted A Header Manager , If B The request header is filled in , So the header manager is B It doesn't work in the interface .
database : The database information is configured in the configuration file , Support 3 Species database ,oracle,sqlserver.mysql Preset in the project 3 A database :DB1,DB2,DB3, You can also customize the database in the configuration file , Use ${} Just call the form .
The number of iterations : It should be noted that the number of iterations is 0 That is, the use case does not execute .
Many columns in the template can be added or deleted according to actual needs , Such as , I want to check 5 A field , So in part101 Just add a few columns later , At the same time in the corresponding section101 Add the same number of columns after ; If two dynamic parameters are used , It's just dyparam001 Just add a column after , Use ${dyparam002} quote .
3、 client Click the select button to select the use case file , Then select the corresponding interface module in the use case file first , Click Start , You can test the interface force , The result of interface success or error report appears in the window . The right side shows that the interface is successful 、 Failure 、 Abnormal data analysis .
analysis JSON Button implementation interface response is parsed into JSON Format , It is convenient to fill in the data verification in the use case file .
After the implementation of the interface use case is completed , Click on excel Report and html The report , You can view the report of this interface execution , Facilitate the analysis of later interface test .
After an error is reported on the execution interface , We can click the view log button , View the request of the executed interface , Respond to And then analyze the cause of interface error .
In view of the space limit , Unable to display documents and project source code , Those who need project practice can pay attention to it and click the link below to get it for free
copyright notice
author[Program yuanxia],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201311048307833.html
The sidebar is recommended
- Django ORM details - fields, attributes, operations
- Python web crawler - crawling cloud music review (3)
- Stroke list in python (bottom)
- What cat is the most popular? Python crawls the whole network of cat pictures. Which one is your favorite
- [algorithm learning] LCP 06 Take coins (Java / C / C + + / Python / go / trust)
- Python shows the progress of downloading files from requests
- Solve the problem that Django celery beat prompts that the database is incorrectly configured and does not support multiple databases
- Bamboolib: this will be one of the most useful Python libraries you've ever seen
- Python quantitative data warehouse construction 3: data drop library code encapsulation
- The source code and implementation of Django CSRF Middleware
guess what you like
-
Python hashlib module
-
The cover of Python 3 web crawler development (Second Edition) has been determined!
-
The introduction method of executing Python source code or Python source code file (novice, please enter the old bird and turn left)
-
[Python basics] explain Python basic functions in detail, including teaching and learning
-
Python web crawler - crawling cloud music review (4)
-
The first step of scientific research: create Python virtual environment on Linux server
-
Writing nmap scanning tool in Python -- multithreaded version
-
leetcode 2057. Smallest Index With Equal Value(python)
-
Bamboolib: this will be one of the most useful Python libraries you've ever seen
-
Python crawler actual combat, requests module, python realizes capturing a video barrage
Random recommended
- [algorithm learning] 1108 IP address invalidation (Java / C / C + + / Python / go / trust)
- Test platform series (71) Python timed task scheme
- Java AES / ECB / pkcs5padding encryption conversion Python 3
- Loguru: the ultimate Python log solution
- Blurring and anonymizing faces using OpenCV and python
- How fast Python sync and async execute
- Python interface automation test framework (basic) -- common data types list & set ()
- Python crawler actual combat, requests module, python realizes capturing video barrage comments of station B
- Python: several implementation methods of multi process
- Sword finger offer II 054 Sum of all values greater than or equal to nodes | 538 | 1038 (Java / C / C + + / Python / go / trust)
- How IOS developers learn python programming 3-operator 2
- How IOS developers learn python programming 2-operator 1
- [Python applet] 8 lines of code to realize file de duplication
- Python uses the pynvml tool to obtain the working status of GPU
- Data mining: Python actual combat multi factor analysis
- Manually compile opencv on MacOS and Linux and add it to Python / C + + / Java as a dependency
- Use Python VTK to batch read 2D slices and display 3D models
- Complete image cutting using Python version VTK
- Python interface automation test framework (basic) -- common data types Dict
- Django (make an epidemic data report)
- Python specific text extraction in actual combat challenges the first step of efficient office
- Daily python, Part 8 - if statement
- Django model class 1
- The same Python code draws many different cherry trees. Which one do you like?
- Python code reading (Chapter 54): Fibonacci sequence
- Django model class 2
- Python crawler Basics
- Mapping 3D model surface distances using Python VTK
- How to implement encrypted message signature and verification in Python -- HMAC
- leetcode 1945. Sum of Digits of String After Convert(python)
- leetcode 2062. Count Vowel Substrings of a String(python)
- Analysis of Matplotlib module of Python visualization
- Django permission management
- Python integrated programming -- visual hot search list and new epidemic situation map
- [Python data collection] scripy realizes picture download
- Python interface automation test framework (basic part) -- loop statement of process control for & while
- Daily python, Chapter 9, while loop
- Van * Python | save the crawled data with docx and PDF
- Five life saving Python tips
- Django frequency control