version: "1.0"
meta:
name: "Hello World Test"
description: "Test basic CLI echo command"
target:
type: cli
timeout: 10
steps:
- name: "Execute echo command"
action: exec
command: echo "Hello World"
- name: "Verify output contains Hello"
action: assert
assertion:
type: stdout_contains
expected: "Hello World"
- name: "Verify exit code is 0"
action: assert
assertion:
type: exit_code
expected: 0version: "1.0"
meta:
name: "API Health Check"
description: "Test API health endpoint"
target:
type: api
base_url: "http://localhost:8000"
timeout: 10
steps:
- name: "Call health endpoint"
action: exec
method: GET
path: "/health"
- name: "Verify status is 200"
action: assert
assertion:
type: status_code
expected: 200
- name: "Verify response contains status"
action: assert
assertion:
type: json_path
path: "$.status"
expected: "ok"version: "1.0"
meta:
name: "TUI Navigation Test"
description: "Test TUI application navigation"
target:
type: tui
start_command: "my-tui-app"
timeout: 30
steps:
- name: "Wait for TUI to load"
action: wait
duration: 2
- name: "Send key sequence"
action: exec
input: "\t\n" # Tab then Enter
- name: "Verify screen content"
action: assert
assertion:
type: screen_contains
expected: "Main Menu"version: "1.0"
meta:
name: "Conditional Test"
description: "Test with conditional steps"
target:
type: cli
timeout: 60
steps:
- name: "Run build command"
action: exec
command: npm run build
timeout: 60
on_error: continue
- name: "Check if dist exists"
action: exec
command: ls dist/
timeout: 5version: "1.0"
meta:
name: "Test with Variables"
description: "Demonstrate variable usage"
target:
type: cli
vars:
greeting: "Hello"
name: "World"
timeout: 10
steps:
- name: "Use variables in command"
action: exec
command: echo "${vars.greeting} ${vars.name}!"
timeout: "${vars.timeout}"
- name: "Verify output"
action: assert
assertion:
type: stdout_contains
expected: "Hello World!"version: "1.0"
meta:
name: "Env Var Test"
description: "Test environment variable access"
target:
type: cli
steps:
- name: "Use environment variable"
action: exec
command: echo "User: ${env.USERNAME}"
- name: "Verify output"
action: assert
assertion:
type: stdout_contains
expected: "User:"version: "1.0"
meta:
name: "Complex CLI Test"
description: "Multiple commands with assertions"
target:
type: cli
timeout: 30
steps:
- name: "Create test directory"
action: exec
command: mkdir -p /tmp/test_dir
- name: "Verify directory creation"
action: assert
assertion:
type: exit_code
expected: 0
- name: "Create test file"
action: exec
command: echo "test content" > /tmp/test_dir/file.txt
- name: "Read file content"
action: exec
command: cat /tmp/test_dir/file.txt
- name: "Verify file content"
action: assert
assertion:
type: stdout_contains
expected: "test content"
- name: "Clean up"
action: exec
command: rm -rf /tmp/test_dir
- name: "Verify cleanup exit code"
action: assert
assertion:
type: exit_code
expected: 0# First, list all projects to find the one to delete
result = list_projects()
# Returns: "📋 测试项目列表:\n • auth-module (cli)..."
# Get project details to confirm
result = get_project(project_id="legacy-project-id")
# Returns project details with all test cases
# Delete the project (permanent!)
result = delete_project(project_id="legacy-project-id")
# Returns: "✅ 项目已删除: legacy-project-id"
# Or: "❌ 删除失败: legacy-project-id"# Get project details to find case ID
result = get_project(project_id="auth-module")
# Returns project with cases: {"login-test": {...}, "logout-test": {...}}
# Delete specific test case
result = delete_case(
project_id="auth-module",
case_id="login-test-id"
)
# Returns: "✅ 测试用例已删除\n 名称: login-test\n ID: login-test-id"
# Or: "❌ 删除失败\n 项目或测试用例未找到"# List all projects
projects = list_projects()
# Delete multiple old projects
for project_id in ["old-project-1", "old-project-2"]:
result = delete_project(project_id=project_id)
print(result)
# Delete multiple test cases from a project
project = get_project(project_id="my-project")
cases_to_delete = ["case-1", "case-2", "case-3"]
for case_id in cases_to_delete:
result = delete_case(
project_id="my-project",
case_id=case_id
)
print(result)# List all templates
result = list_templates()
# Returns: "📋 模板库 (5 个):\n • API Health Check..."
# Filter by category
result = list_templates(category="api")
# Returns only API templates
# Filter by target type
result = list_templates(target_type="cli")
# Returns only CLI templates
# Filter by tag
result = list_templates(tag="auth")
# Returns templates with "auth" tag# Create a reusable API test template
result = create_template(
name="API Health Check",
description="Generic health check for API endpoints",
target_type="api",
category="api",
tags=["health", "monitoring"],
dsl_template="""version: "1.0"
meta:
name: "${test_name}"
description: "Health check for ${endpoint}"
target:
type: api
base_url: "${base_url}"
steps:
- name: "Call ${endpoint}"
action: exec
method: GET
path: "${endpoint}"
- name: "Verify status code"
action: assert
assertion:
type: status_code
expected: ${expected_status}
"""
)
# Returns: "✅ 模板创建成功\n 名称: API Health Check\n ID: xxx\n 变量: 4 个"# Create a test case from a template
result = instantiate_template(
template_id="template-uuid",
project_id="my-project",
case_name="User API Health Check",
variables={
"test_name": "User Service Health",
"endpoint": "/api/users/health",
"base_url": "http://localhost:8000",
"expected_status": "200"
}
)
# Returns: "✅ 模板实例化成功\n 模板: API Health Check\n 用例: User API Health Check\n ID: case-uuid\n 步骤数: 2"# Convert an existing test case to a template
result = create_template_from_case(
project_id="auth-module",
case_id="login-test-id",
template_name="User Login Template",
description="Reusable login test template",
category="auth",
variable_mappings={
"http://localhost:3000": "base_url",
"test@example.com": "email",
"password123": "password"
}
)
# Returns: "✅ 模板创建成功\n 名称: User Login Template\n ID: template-uuid\n 变量: 3 个\n 来源: login-test"# Update an existing template
result = update_template(
template_id="template-uuid",
name="Updated Template Name",
description="Updated description",
category="workflow",
tags=["updated", "production"]
)
# Returns: "✅ 模板更新成功\n 名称: Updated Template Name\n ID: template-uuid"# Delete a template
result = delete_template(template_id="old-template-id")
# Returns: "✅ 模板已删除: Old Template Name"
# Or: "❌ 模板未找到: old-template-id"Template DSL uses ${variable_name} placeholders:
version: "1.0"
meta:
name: "${test_name}"
description: "Test for ${service_name}"
target:
type: cli
vars:
timeout: ${timeout_seconds}
steps:
- name: "Execute ${command_name}"
action: exec
command: "${command}"
timeout: ${timeout_seconds}
- name: "Verify output"
action: assert
assertion:
type: stdout_contains
expected: "${expected_output}"When instantiating, variables are replaced:
instantiate_template(
template_id="...",
project_id="...",
case_name="My Test",
variables={
"test_name": "Database Backup Test",
"service_name": "PostgreSQL",
"command_name": "backup",
"command": "pg_dump mydb > backup.sql",
"timeout_seconds": "60",
"expected_output": "backup complete"
}
)The resulting test case will have all variables replaced with the provided values.