record_HTTP_API_via_mitmproxy Record http api data via mitmproxy flask_http_methods_demo A simple Flask-based website that includes several HTTP requests methods that can be used for demo API testing
app_apibase.py : core class, include login, http requests(get, post...) and return data by json format.
jsonschema_handle.py:
- Read .json file and return JSON schema.
- Validate JSON schema and add logs to the Allure report.
Manage test cases by pytest framework. Feature coverage:
- API in home page (done)
base_config.py : Read 'config.yaml' file to get base_url, account and password, ...
Save the logs generated by the scripts
Save reports of API tests generated by Allure.
csv_parse.py: convert .csv to test case handle_request.py: handle request_url, params, payload for each test case, and send http request. commmon_funs.py : some common functions report_post_handle.py: analyze allure report write_csv.py: Record Http API requests data to .csv file
- Install python 3.7+
- Download code.
- In current folder, run
pip install -r requirement.txt
- Install allure 2.1.38+ via “allure2”
- Download or generate the
config.yaml
file by referring to the 'config_sample.yaml' in the 'config' subfolder. - Execute
python3 run_api_cases.py
, and check reports. Also, we can specify the runt environment in the first parameter, e.g.python3 run_api_cases.py prod
- Use the script "Assist-Tools/record_HTTP_API_via_mitmproxy/record_http_apis.py" to capture the http api request data during the product usage to a csv file.
- Put the csv file obtained in the previous step under "Assist-Tools/generate_newcase_from_apirecord_csv", and run "generate_newcases_from_api_record.py" to generate the new api use case data file "*_cases.csv" In addition, there are new api jsonschema files under new_jsonschema_files_dir, and put under "cases/jsonfiles".
- Extract parameter variables: The csv data obtained in the previous step has a field named "var_extract", which is in essence a dict that can be extracted from the response data of the api and stored as a variable for subsequent api calls.
For example, the field is {"name":"$. .name"}, it means that the name field in the json returned by the api is stored in the variable name, which can be referenced by
${name} in subsequent use cases, where "$ . .name" is a jsonpath expression. - "Assist-Tools/flask_http_methods_demo" is a simple Flask project to create some http apis locally for testing the framework.
- Use "record_http_apis.py" to capture the http api interface data accessed by the product.
- run "generate_newcases_from_api_record.py" to process the captured csv data and generate test data for the new api.
- Adjust the test data of the new api as needed and add it to the test framework.