Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 3.03 KB

readme_EN.md

File metadata and controls

55 lines (44 loc) · 3.03 KB

Http API Automation with Python 3

Assist-Tools

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

bases

app_apibase.py : core class, include login, http requests(get, post...) and return data by json format.

jsonschema_handle.py:

  1. Read .json file and return JSON schema.
  2. Validate JSON schema and add logs to the Allure report.

cases

Manage test cases by pytest framework. Feature coverage:

  • API in home page (done)

config

base_config.py : Read 'config.yaml' file to get base_url, account and password, ...

logs

Save the logs generated by the scripts

reports

Save reports of API tests generated by Allure.

utilities

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

Usage

  1. Install python 3.7+
  2. Download code.
  3. In current folder, run pip install -r requirement.txt
  4. Install allure 2.1.38+ via “allure2”
  5. Download or generate the config.yaml file by referring to the 'config_sample.yaml' in the 'config' subfolder.
  6. 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

Additional suggestions:

  1. 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.
  2. 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".
  3. 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.
  4. "Assist-Tools/flask_http_methods_demo" is a simple Flask project to create some http apis locally for testing the framework.

Overview of the main steps

  1. Use "record_http_apis.py" to capture the http api interface data accessed by the product.
  2. run "generate_newcases_from_api_record.py" to process the captured csv data and generate test data for the new api.
  3. Adjust the test data of the new api as needed and add it to the test framework.