Scripting with Executor
The Executor enables JSON keyword-driven testing, where test actions are defined as JSON arrays and executed programmatically.
JSON Keyword-Driven Testing
Create a JSON file (e.g., 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}
}]
]
}
Executing JSON Files via Python
from je_api_testka import execute_action, read_action_json
execute_action(read_action_json("test_actions.json"))
Executing a Directory of JSON Files
from je_api_testka import execute_files, get_dir_files_as_list
execute_files(get_dir_files_as_list("path/to/json_dir"))
Adding Custom Commands
from je_api_testka import add_command_to_executor, execute_action
def my_custom_function(url):
print(f"Custom test on: {url}")
add_command_to_executor({"my_test": my_custom_function})
execute_action([
["my_test", ["http://example.com"]]
])
Built-in Executor Commands
Command |
Description |
|---|---|
|
Test API with requests backend |
|
Test API with httpx sync backend |
|
Test API with httpx async backend (run synchronously) |
|
Generate HTML report data |
|
Generate HTML report file |
|
Generate JSON report data |
|
Generate JSON report file |
|
Generate XML report data |
|
Generate XML report file |
|
Execute nested action list |
|
Execute actions from multiple files |
|
Dynamically load a package into executor |
|
Dynamically load a package into callback executor |
|
Add route to mock server |
|
Start mock server |