Table of contents
Step 1. Create a new common_function.py file in the common folder and encapsulate the method
Step 3. Create a new local_config.py file in the common folder
Step 4. Put the values in the local_config.py file into the use case layer, as shown below
Modular test script framework
You need to create independent describable modules, program snippets, and scripts for the application to be tested. These small scripts can be combined to form test case scripts that can be used to run specific tests independently.
scene one:
The development changed the access_token interface address from /cgi-bin/token to /cgi-bin/get_token or modified parameters, etc. ==> The development adjusted the commonly used interface information; this scenario will cause most parts of the test script to need maintenance. And I am worried about future adjustments; therefore, I use a modular testing framework to solve it.
Since the token acquisition operation is used very frequently in the code, it is made public.
Step 1. Create a new common_function.py file in the common folder and encapsulate the method
Write code:
# encoding: utf-8
# @author: Jeffrey
# @file: commom_function.py
# @time: 2022/7/26 21:01
# @desc: 模块化框架
import jsonpath
def get_access_token_value(session_obj):
"""获取access_token的值"""
url_params = {"grant_type": "client_credential",
"appid": "wxf14419077f707856",
"secret": "92a113bd4b5ffdc72144740dc7123c99"}
response = session_obj.get(url="https://api.weixin.qq.com/cgi-bin/token",
params=url_params)
# 获取响应json中的access_token的值
token_value = jsonpath.jsonpath(response.json(), "$.access_token")[0]
return token_value
Step 2. Import the public module in the test_create_user_tag_api.py file and delete the original redundant code; as shown below
Benefits of the above code: 1. Reduce code redundancy; 2. Convenient maintenance (scenario described above)
Scene two:
The company's test environment address changes, such as switching the domain name from api.weixin.qq.com to 192.168.1.12
Step 3. Create a new local_config.py file in the common folder
Step 4. Put the values in the local_config.py file into the use case layer, as shown below
View execution results
Note: When executing through the above use case layer, each use case must obtain access_token once. In fact, the access_token is valid for 2 hours each time it is obtained, which will be solved later.
The following are relatively good learning tutorial resources that I have collected. Although they are not very valuable, if you happen to need them, you can leave a message in the comment area [777] and just take them away.
Friends who want to get information, please like + comment + collect , three times in a row!
After three consecutive rounds , I will send you private messages one by one in the comment area~