Skip to main content
Glama

🚀 Karate 功能图分析器

一个强大的 MCP(模型上下文协议)工具,用于分析 Karate 框架功能文件并生成交互式依赖图。

Python Tests License


📋 目录


Related MCP server: GID MCP Server

✨ 功能特性

核心能力

  • 🔍 功能文件解析 - 使用 Gherkin 语法解析 Karate 功能文件

  • 🎯 依赖分析 - 提取并分析依赖关系(工作流、API、页面、数据库)

  • 📊 交互式可视化 - 生成带有图例的精美 HTML 图表

  • 🎫 Jira 集成 - 提取并跟踪 Jira 标签 (@PROJ-123)

  • 🔄 影响分析 - 在组件发生变更时识别受影响的测试用例

  • 📈 多项目支持 - 管理和分析多个项目

  • 💾 导出/导入 - 将图表导出为 JSON/GraphML 格式

  • 性能优化 - 通过缓存和索引实现快速分析

可视化特性

  • 🎨 按类型进行颜色编码的节点(测试、工作流、API、页面、数据库)

  • 🔍 带有元数据的交互式工具提示(文件路径、行号、Jira 标签)

  • 🖱️ 点击以高亮显示连接和依赖关系

  • 📊 右上角的图例,解释颜色和形状含义

  • 🔄 物理模拟,实现自动布局

  • 🎯 影响视图,突出显示已更改的组件和受影响的测试


🚀 快速入门

1. 安装依赖

pip install -e .
pip install pyvis  # For visualization

2. 运行演示

# Set UTF-8 encoding (Windows)
$env:PYTHONIOENCODING="utf-8"

# Run large project demo
python test_large_project.py

3. 查看结果

cd output
start ecommerce-platform_full.html

📦 安装

前置条件

  • Python 3.8 或更高版本

  • pip 包管理器

从源码安装

# Clone repository
git clone <repository-url>
cd karate-feature-graph-analyzer

# Install dependencies
pip install -e .

# Install visualization library
pip install pyvis

# Verify installation
pytest tests/ -v

依赖项

核心依赖(自动安装):

  • networkx - 图操作

  • hypothesis - 基于属性的测试

  • pydantic - 数据验证

可选依赖:

  • pyvis - 交互式可视化


💻 使用方法

基本用法

from karate_graph_analyzer.mcp_interface.mcp_tool import KarateGraphAnalyzerTool

# Initialize tool
tool = KarateGraphAnalyzerTool()

# Register project
tool.register_project(
    name="my-project",
    root_path="/path/to/karate/project",
    feature_file_patterns=["**/*.feature"]
)

# Analyze project
analysis = tool.analyze_project("my-project")
print(f"Found {analysis['statistics']['total_nodes']} nodes")

# Query dependencies
deps = tool.query_dependencies("tc_0001", transitive=True)
print(f"Found {deps['count']} dependencies")

# Impact analysis
impact = tool.impact_analysis("api_0001")
print(f"Affected: {impact['total_count']} test cases")

# Export graph
export = tool.export_graph("my-project", format="json")
with open("graph.json", "w") as f:
    f.write(export['data'])

可视化

from karate_graph_analyzer.visualization.graph_visualizer import GraphVisualizer

# Get graph
graph = tool.graphs["my-project"]

# Create visualizer
visualizer = GraphVisualizer(graph)

# Render full graph
visualizer.render("output/graph.html", height="900px")

# Render impact view
visualizer.render_impact_view(
    changed_component_id="api_0001",
    affected_test_case_ids=["tc_0001", "tc_0002"],
    output_path="output/impact.html"
)

命令行(通过脚本)

# Analyze large project
python test_large_project.py

# Output will be in output/ directory:
# - ecommerce-platform_full.html (full graph)
# - ecommerce-platform_impact.html (impact view)
# - ecommerce-platform_graph.json (graph data)
# - LARGE_PROJECT_ANALYSIS_REPORT.md (detailed report)

📁 项目结构

karate-feature-graph-analyzer/
├── src/karate_graph_analyzer/
│   ├── models.py                    # Data models
│   ├── parser/                      # Feature file parsing
│   │   └── feature_parser.py
│   ├── graph/                       # Graph construction
│   │   └── graph_builder.py
│   ├── analyzer/                    # Dependency analysis
│   │   └── dependency_analyzer.py
│   ├── mcp_interface/               # MCP protocol
│   │   └── mcp_tool.py
│   ├── storage/                     # Project registry
│   │   └── project_registry.py
│   ├── cache/                       # AST caching
│   │   └── cache_manager.py
│   ├── visualization/               # Graph visualization
│   │   └── graph_visualizer.py
│   └── logging_config.py            # Logging setup
│
├── tests/
│   ├── unit/                        # 306 unit tests
│   ├── integration/                 # Integration tests
│   └── fixtures/                    # Test data
│
├── output/                          # Generated files
│   ├── ecommerce-platform_full.html
│   ├── ecommerce-platform_impact.html
│   ├── ecommerce-platform_graph.json
│   ├── LARGE_PROJECT_ANALYSIS_REPORT.md
│   └── README.md
│
├── test_project_demo/               # Small demo project
├── test_project_large/              # Large demo project (e-commerce)
├── examples/                        # Usage examples
├── docs/                            # Documentation
│   ├── API.md
│   └── jira_tag_extraction.md
│
├── test_large_project.py            # Demo script
├── pyproject.toml                   # Project config
├── pytest.ini                       # Test config
└── README.md                        # This file

📚 文档

核心文档

规范


🎯 示例

示例 1:分析演示项目

# Run demo
python test_large_project.py

# View results
cd output
start ecommerce-platform_full.html

你将看到

  • 84 个节点(73 个测试用例,6 个工作流,3 个页面,1 个 API,1 个数据库)

  • 26 条边(依赖关系)

  • 带有图例的交互式图表

  • 按类型进行颜色编码

  • 带有元数据的悬停工具提示

示例 2:影响分析

# Find what tests are affected by API change
impact = tool.impact_analysis("api_0001")

print(f"Changed: {impact['changed_component']}")
print(f"Affected: {impact['total_count']} test cases")

for tc in impact['affected_test_cases']:
    print(f"  - {tc['name']} (depth: {tc['depth']})")
    if tc['jira_tags']:
        print(f"    Jira: {', '.join(tc['jira_tags'])}")

输出

Changed: api_0001
Affected: 14 test cases
  - Successful login (depth: 1)
    Jira: @AUTH-101
  - Get user profile (depth: 1)
    Jira: @USER-101
  ...

示例 3:查找公共组件

# Find reusable components across projects
common = tool.find_common_components(["project1", "project2"])

for comp in common['components']:
    print(f"{comp['component_type']}: {comp['identifier']}")
    print(f"  Used in {comp['usage_count']} projects")
    print(f"  Projects: {', '.join(comp['projects'])}")

🧪 测试

运行所有测试

# Run all tests
pytest tests/ -v

# Run specific test suite
pytest tests/unit/ -v
pytest tests/integration/ -v

# Run with coverage
pytest tests/ --cov=src/karate_graph_analyzer --cov-report=html

测试统计

  • 总测试数: 306

  • 通过: 306 (100%)

  • 失败: 0

  • 跳过: 1

  • 覆盖率: 全面

测试类别

  • 单元测试 (tests/unit/) - 测试单个组件

  • 集成测试 (tests/integration/) - 测试组件交互

  • 属性测试 (可选) - 使用 Hypothesis 进行基于属性的测试


🎨 可视化指南

理解图例

当你打开可视化 HTML 文件时,查看右上角的图例:

📊 Legend
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🟢 Test Case - Scenario hoặc test
🔵 Workflow - Reusable workflow
🟠 API - API endpoint
🟣 Page - Page object
🔴 Database - Database operation
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💡 Tip: Hover để xem chi tiết
🖱️ Click để highlight connections
🔍 Scroll để zoom in/out

交互功能

  1. 悬停 - 将鼠标移动到节点上以查看工具提示,包含:

    • 节点名称

    • 节点类型

    • 文件路径

    • 行号

    • Jira 标签

  2. 点击 - 点击节点以高亮显示:

    • 所选节点

    • 所有连接的节点

    • 所有连接的边

  3. 缩放 - 滚动鼠标滚轮进行放大/缩小

  4. 平移 - 拖动背景以移动视图

  5. 重定位 - 拖动节点以重新排列布局


🔧 配置

解析器配置

from karate_graph_analyzer.models import ParserConfig

config = ParserConfig(
    jira_tag_patterns=[
        r'@[A-Z]+-\d+',      # @PROJ-123
        r'@[a-z]+-\d+',      # @proj-123
        r'@[A-Z]+_\d+',      # @PROJ_123
    ],
    workflow_directories=['workflows', 'common'],
    page_object_directories=['pages', 'page-objects'],
    variable_patterns=[r'\$\{(\w+)\}'],
    api_extraction_rules={
        'extract_from_variables': True,
        'extract_from_strings': True,
    }
)

# Use custom config
tool.register_project(
    name="my-project",
    root_path="/path/to/project",
    parser_config=config
)

📊 关键指标

性能

  • 分析时间: 4 个文件 < 1 秒

  • 查询时间: 依赖查询 < 10ms

  • 影响分析: 6 个受影响测试 < 50ms

  • 导出时间: 9 个节点 < 100ms

  • 可视化: 渲染 < 1 秒

可扩展性

  • 测试规模: 84 个节点,26 条边

  • 支持规模: 1000+ 个节点(预估)

  • 内存: 缓存机制高效

  • 存储: JSON 格式,每个节点约 500 字节


🤝 贡献

欢迎贡献!请遵循以下准则:

  1. Fork 本仓库

  2. 创建功能分支 (git checkout -b feature/amazing-feature)

  3. 提交你的更改 (git commit -m 'Add amazing feature')

  4. 推送到分支 (git push origin feature/amazing-feature)

  5. 开启 Pull Request

开发环境设置

# Clone your fork
git clone <your-fork-url>
cd karate-feature-graph-analyzer

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run linter
flake8 src/

# Format code
black src/

📝 许可证

本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。


🙏 致谢

  • Karate Framework - 出色的 BDD 测试框架

  • NetworkX - 图操作库

  • Pyvis - 交互式可视化库

  • Hypothesis - 基于属性的测试库


📞 支持

文档

示例

问题反馈

如果你遇到任何问题:

  1. 查看文档

  2. 查看示例

  3. 在 GitHub 上提交 Issue


🎉 快速链接


使用规范驱动开发 (SDD) ❤️ 构建

状态: ✅ 生产就绪 版本: 1.0.0 最后更新: 2026年4月30日

🚀 分析愉快!

Install Server
A
license - permissive license
B
quality
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/duyngo91/karate-graph-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server