This page explains how to export MagicPod test results to formats such as CSV, Spreadsheet, or Excel.
Table of contents
Using the MagicPod Web API
This method uses the MagicPod Web API to convert JSON response data into CSV. By incorporating this into your scripts or CI/CD pipelines, you can also automate the retrieval and storage of test results.
For details on the MagicPod Web API specifications, please refer to the following.
The following Python script example uses the endpoint GET /api/v1.0/{org}/{project}/batch-runs/ to retrieve batch run results and output them as a CSV file.
import requests
import csv
API_TOKEN = "YOUR_API_TOKEN"
ORG = "ORGANIZATION_NAME"
PROJECT = "PROJECT_NAME"
BASE_URL = f"https://app.magicpod.com/api/v1.0/{ORG}/{PROJECT}"
HEADERS = {
"Authorization": f"Token {API_TOKEN}",
"accept": "application/json"
}
# Retrieve the 20 most recent batch runs
resp = requests.get(
f"{BASE_URL}/batch-runs/?count=20",
headers=HEADERS
)
data = resp.json()
batch_runs = data["batch_runs"]
# Retrieve details of each batch run and output to CSV
with open("test_results.csv", "w", newline="", encoding="utf-8-sig") as f:
writer = csv.writer(f)
writer.writerow([
"batch_run_number", "status",
"test_setting_name",
"started_at", "finished_at",
"pattern_name", "device_info",
"test_case_number", "test_case_name",
"data_pattern_number",
"test_case_status", "error_message"
])
for run in batch_runs:
num = run["batch_run_number"]
detail = requests.get(
f"{BASE_URL}/batch-run/{num}/",
headers=HEADERS,
params={"errors": "true"},
).json()
for pattern in detail.get("test_cases", {}).get("details", []):
pat = pattern.get("pattern", {})
pattern_name = pattern.get("pattern_name") or ""
device_info = " / ".join(
filter(None, [pat.get("os"), pat.get("model"), pat.get("browser")])
)
for tc in pattern.get("results", []):
tc_info = tc.get("test_case", {})
tc_number = tc_info.get("number", "")
tc_name = tc_info.get("name", "")
base_row = [
num,
detail.get("status"),
detail.get("test_setting_name"),
detail.get("started_at"),
detail.get("finished_at"),
pattern_name,
device_info,
tc_number,
tc_name,
]
data_patterns = tc.get("data_patterns")
if data_patterns:
for dp in data_patterns:
dp_errors = dp.get("errors") or []
dp_error_msg = "; ".join(
e.get("message") or "" for e in dp_errors
)
writer.writerow(base_row + [
dp.get("number", ""),
dp.get("status", ""),
dp_error_msg,
])
else:
errors = tc.get("errors") or []
error_msg = "; ".join(
e.get("message") or "" for e in errors
)
writer.writerow(base_row + [
"",
tc.get("status"),
error_msg,
])
print("Output to test_results.csv")Example of the output CSV file
Using the MagicPod MCP Server
This method involves setting up the MagicPod MCP server so you can give natural language instructions to an AI agent and have it output your test results.