腳本化執行器
Executor 實現了 JSON 關鍵字驅動測試,測試動作以 JSON 陣列定義, 並透過程式化方式執行。
JSON 關鍵字驅動測試
建立一個 JSON 檔案(例如 test_actions.json):
{
"api_testka": [
["AT_test_api_method", {
"http_method": "get",
"test_url": "http://httpbin.org/get",
"result_check_dict": {"status_code": 200}
}],
["AT_test_api_method", {
"http_method": "post",
"test_url": "http://httpbin.org/post",
"params": {"task": "new task"},
"result_check_dict": {"status_code": 200}
}]
]
}
透過 Python 執行 JSON 檔案
from je_api_testka import execute_action, read_action_json
execute_action(read_action_json("test_actions.json"))
執行整個目錄的 JSON 檔案
from je_api_testka import execute_files, get_dir_files_as_list
execute_files(get_dir_files_as_list("path/to/json_dir"))
新增自訂命令
from je_api_testka import add_command_to_executor, execute_action
def my_custom_function(url):
print(f"自訂測試:{url}")
add_command_to_executor({"my_test": my_custom_function})
execute_action([
["my_test", ["http://example.com"]]
])
內建 Executor 命令
命令 |
說明 |
|---|---|
|
使用 requests 後端測試 API |
|
使用 httpx 同步後端測試 API |
|
使用 httpx 非同步後端測試 API(同步呼叫) |
|
產生 HTML 報告資料 |
|
產生 HTML 報告檔案 |
|
產生 JSON 報告資料 |
|
產生 JSON 報告檔案 |
|
產生 XML 報告資料 |
|
產生 XML 報告檔案 |
|
執行巢狀動作列表 |
|
從多個檔案執行動作 |
|
動態載入套件到執行器 |
|
動態載入套件到回呼執行器 |
|
新增路由到模擬伺服器 |
|
啟動模擬伺服器 |