Skip to content

Commit a96f976

Browse files
committed
首次提交:初始化项目
0 parents  commit a96f976

32 files changed

+5924
-0
lines changed

.env.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Environment Variables for Midscene Python
2+
3+
# AI Model Configuration
4+
MIDSCENE_AI_PROVIDER=openai
5+
MIDSCENE_AI_MODEL=gpt-4-vision-preview
6+
MIDSCENE_AI_API_KEY=your-api-key-here
7+
# MIDSCENE_AI_BASE_URL=https://api.openai.com
8+
9+
# Execution Settings
10+
MIDSCENE_CONCURRENT=1
11+
MIDSCENE_CONTINUE_ON_ERROR=false
12+
MIDSCENE_GENERATE_REPORT=true
13+
14+
# Logging
15+
MIDSCENE_LOG_LEVEL=INFO
16+
MIDSCENE_LOG_FILE=midscene.log
17+
18+
# Development Settings
19+
MIDSCENE_DEBUG=false
20+
MIDSCENE_CACHE_ENABLED=true

.gitignore

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.nox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
*.py,cover
49+
.hypothesis/
50+
.pytest_cache/
51+
52+
# Translations
53+
*.mo
54+
*.pot
55+
56+
# Django stuff:
57+
*.log
58+
local_settings.py
59+
db.sqlite3
60+
db.sqlite3-journal
61+
62+
# Flask stuff:
63+
instance/
64+
.webassets-cache
65+
66+
# Scrapy stuff:
67+
.scrapy
68+
69+
# Sphinx documentation
70+
docs/_build/
71+
72+
# PyBuilder
73+
target/
74+
75+
# Jupyter Notebook
76+
.ipynb_checkpoints
77+
78+
# IPython
79+
profile_default/
80+
ipython_config.py
81+
82+
# pyenv
83+
.python-version
84+
85+
# pipenv
86+
Pipfile.lock
87+
88+
# PEP 582
89+
__pypackages__/
90+
91+
# Celery stuff
92+
celerybeat-schedule
93+
celerybeat.pid
94+
95+
# SageMath parsed files
96+
*.sage.py
97+
98+
# Environments
99+
.env
100+
.venv
101+
env/
102+
venv/
103+
ENV/
104+
env.bak/
105+
venv.bak/
106+
107+
# Spyder project settings
108+
.spyderproject
109+
.spyproject
110+
111+
# Rope project settings
112+
.ropeproject
113+
114+
# mkdocs documentation
115+
/site
116+
117+
# mypy
118+
.mypy_cache/
119+
.dmypy.json
120+
dmypy.json
121+
122+
# Pyre type checker
123+
.pyre/
124+
125+
# Midscene specific
126+
reports/
127+
.midscene/
128+
*.log
129+
130+
# IDE
131+
.vscode/
132+
.idea/
133+
*.swp
134+
*.swo
135+
136+
# OS
137+
.DS_Store
138+
Thumbs.db

Makefile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.PHONY: help install dev test lint format clean build docs
2+
3+
# Default target
4+
help:
5+
@echo "Available commands:"
6+
@echo " install Install package and dependencies"
7+
@echo " dev Install development dependencies"
8+
@echo " test Run tests"
9+
@echo " lint Run linting"
10+
@echo " format Format code"
11+
@echo " clean Clean build artifacts"
12+
@echo " build Build package"
13+
@echo " docs Build documentation"
14+
15+
# Install package
16+
install:
17+
pip install -e .
18+
19+
# Install development dependencies
20+
dev:
21+
pip install -e ".[dev,docs]"
22+
pre-commit install
23+
24+
# Run tests
25+
test:
26+
pytest tests/ -v --cov=midscene --cov-report=html --cov-report=term-missing
27+
28+
# Run tests with specific markers
29+
test-unit:
30+
pytest tests/ -v -m "unit"
31+
32+
test-integration:
33+
pytest tests/ -v -m "integration"
34+
35+
# Linting
36+
lint:
37+
ruff check midscene/ tests/
38+
mypy midscene/
39+
40+
# Format code
41+
format:
42+
black midscene/ tests/ examples/
43+
isort midscene/ tests/ examples/
44+
ruff check --fix midscene/ tests/
45+
46+
# Clean build artifacts
47+
clean:
48+
rm -rf build/
49+
rm -rf dist/
50+
rm -rf *.egg-info/
51+
rm -rf .pytest_cache/
52+
rm -rf .coverage
53+
rm -rf htmlcov/
54+
find . -type d -name __pycache__ -delete
55+
find . -type f -name "*.pyc" -delete
56+
57+
# Build package
58+
build: clean
59+
python -m build
60+
61+
# Build documentation
62+
docs:
63+
mkdocs build
64+
65+
# Serve documentation locally
66+
docs-serve:
67+
mkdocs serve
68+
69+
# Release to PyPI
70+
release: build
71+
twine upload dist/*
72+
73+
# Release to Test PyPI
74+
release-test: build
75+
twine upload --repository testpypi dist/*

README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Midscene Python
2+
3+
Midscene 的 Python 实现版本 - 基于 AI 的自动化框架,支持 Web 和 Android 平台的 UI 自动化操作。
4+
5+
## 概述
6+
7+
Midscene Python 是原 TypeScript/JavaScript 版本的完整移植,保持相同的核心架构和功能特性:
8+
9+
- **自然语言驱动**:使用自然语言描述自动化任务
10+
- **多平台支持**:支持 Web(Selenium/Playwright)和 Android(ADB)
11+
- **AI 模型集成**:支持 GPT-4V、Qwen2.5-VL、Gemini 等多种视觉语言模型
12+
- **可视化调试**:提供详细的执行报告和调试信息
13+
- **缓存机制**:智能缓存提升执行效率
14+
15+
## 项目架构
16+
17+
```
18+
midscene-python/
19+
├── midscene/ # 核心框架
20+
│ ├── core/ # 核心框架
21+
│ │ ├── agent/ # Agent系统
22+
│ │ ├── insight/ # AI推理引擎
23+
│ │ ├── ai_model/ # AI模型集成
24+
│ │ ├── yaml/ # YAML脚本执行器
25+
│ │ └── types.py # 核心类型定义
26+
│ ├── web/ # Web集成
27+
│ │ ├── selenium/ # Selenium集成
28+
│ │ ├── playwright/ # Playwright集成
29+
│ │ └── bridge/ # Bridge模式
30+
│ ├── android/ # Android集成
31+
│ │ ├── device.py # 设备管理
32+
│ │ └── agent.py # Android Agent
33+
│ ├── cli/ # 命令行工具
34+
│ ├── mcp/ # MCP协议支持
35+
│ ├── shared/ # 共享工具
36+
│ └── visualizer/ # 可视化报告
37+
├── examples/ # 示例代码
38+
├── tests/ # 测试用例
39+
└── docs/ # 文档
40+
```
41+
42+
## 技术栈
43+
44+
- **Python 3.9+**:核心运行环境
45+
- **Pydantic**:数据验证和序列化
46+
- **Selenium/Playwright**:Web 自动化
47+
- **OpenCV/Pillow**:图像处理
48+
- **HTTPX/AIOHTTP**:HTTP 客户端
49+
- **Typer**:CLI 框架
50+
- **Loguru**:日志记录
51+
52+
## 快速开始
53+
54+
### 安装
55+
56+
```bash
57+
pip install midscene-python
58+
```
59+
60+
### 基础用法
61+
62+
```python
63+
from midscene import Agent
64+
from midscene.web import SeleniumWebPage
65+
66+
# 创建 Web Agent
67+
with SeleniumWebPage.create() as page:
68+
agent = Agent(page)
69+
70+
# 使用自然语言进行自动化操作
71+
await agent.ai_action("点击登录按钮")
72+
await agent.ai_action("输入用户名 'test@example.com'")
73+
await agent.ai_action("输入密码 'password123'")
74+
await agent.ai_action("点击提交按钮")
75+
76+
# 数据提取
77+
user_info = await agent.ai_extract("提取用户个人信息")
78+
79+
# 断言验证
80+
await agent.ai_assert("页面显示欢迎信息")
81+
```
82+
83+
## 主要特性
84+
85+
### 🤖 AI 驱动的自动化
86+
87+
使用自然语言描述操作,AI 自动理解并执行:
88+
89+
```python
90+
await agent.ai_action("在搜索框中输入'Python教程'并搜索")
91+
```
92+
93+
### 🔍 智能元素定位
94+
95+
支持多种定位策略,自动选择最优方案:
96+
97+
```python
98+
element = await agent.ai_locate("登录按钮")
99+
```
100+
101+
### 📊 数据提取
102+
103+
从页面提取结构化数据:
104+
105+
```python
106+
products = await agent.ai_extract({
107+
"products": [
108+
{"name": "产品名称", "price": "价格", "rating": "评分"}
109+
]
110+
})
111+
```
112+
113+
### ✅ 智能断言
114+
115+
AI 理解页面状态,进行智能断言:
116+
117+
```python
118+
await agent.ai_assert("用户已成功登录")
119+
```
120+
121+
## 许可证
122+
123+
MIT License

0 commit comments

Comments
 (0)