docs: update project structure and add database documentation
- Add tests/ directory to .gitignore - Document database connectivity with pyodbc and config - Add project structure and file organization guidelines - Update installation steps to use requirements.txt - Document new dependencies: pandas, openpyxl, pyodbc
This commit is contained in:
71
CLAUDE.md
71
CLAUDE.md
@@ -12,8 +12,8 @@ This is a Python automation project using Playwright to interact with a Chinese
|
||||
# Activate the virtual environment (Windows)
|
||||
.venv\Scripts\activate
|
||||
|
||||
# Install dependencies
|
||||
pip install playwright
|
||||
# Install all dependencies
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Install Playwright browsers
|
||||
playwright install chromium
|
||||
@@ -23,17 +23,53 @@ playwright install chromium
|
||||
|
||||
```bash
|
||||
# Run the main test script
|
||||
python test_playwright.py
|
||||
python tests/test_playwright.py
|
||||
|
||||
# Run the record script
|
||||
python record.py
|
||||
|
||||
# Run database query test
|
||||
python tests/test_db_query.py
|
||||
```
|
||||
|
||||
## Key Dependencies
|
||||
|
||||
- **playwright==1.57.0**: Browser automation framework
|
||||
- **pyodbc**: SQL Server database connectivity
|
||||
- **pandas**: Data processing and Excel file handling
|
||||
- **openpyxl**: Excel file operations
|
||||
- Uses synchronous API (`playwright.sync_api`)
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
playwrite/
|
||||
├── config/ # Configuration files (database, etc.)
|
||||
├── db/ # Database connection components
|
||||
├── data/ # Data files (excluded from git)
|
||||
├── docs/ # Documentation (e.g., DEPENDENCIES.md)
|
||||
├── tests/ # Test scripts (excluded from git)
|
||||
├── requirements.txt # Python dependencies
|
||||
├── .gitignore # Git ignore rules
|
||||
└── CLAUDE.md # This file
|
||||
```
|
||||
|
||||
## File Organization Rules
|
||||
|
||||
**IMPORTANT**: When creating test scripts, always place them in the `tests/` folder:
|
||||
|
||||
- Test scripts should be prefixed with `test_`
|
||||
- All files in `tests/` are excluded from git tracking
|
||||
- Examples: `tests/test_playwright.py`, `tests/test_db_query.py`
|
||||
|
||||
**Configuration Management**:
|
||||
- Place configuration files in `config/` folder
|
||||
- Database credentials and settings go in `config/database_config.py`
|
||||
|
||||
**Data Storage**:
|
||||
- Use `data/` folder for temporary data files
|
||||
- This folder is excluded from git tracking
|
||||
|
||||
## Architecture
|
||||
|
||||
### Nested Iframe Structure
|
||||
@@ -80,6 +116,35 @@ with page.expect_popup() as popup_info:
|
||||
new_page = popup_info.value
|
||||
```
|
||||
|
||||
### Database Connection
|
||||
|
||||
The project uses `pyodbc` to connect to SQL Server for data queries:
|
||||
|
||||
```python
|
||||
from db.connection import get_connection
|
||||
|
||||
# Using context manager
|
||||
with get_connection() as db:
|
||||
results = db.execute_query("SELECT * FROM table")
|
||||
# Connection automatically closed
|
||||
|
||||
# Using the query helper
|
||||
from db.connection import query_production_orders
|
||||
results = query_production_orders(['ID1', 'ID2', 'ID3'])
|
||||
```
|
||||
|
||||
Database configuration is stored in `config/database_config.py`:
|
||||
```python
|
||||
SQL_SERVER_CONFIG = {
|
||||
'driver': 'ODBC Driver 18 for SQL Server',
|
||||
'server': '192.168.110.114',
|
||||
'database': 'CompanyDB',
|
||||
'username': 'peng',
|
||||
'password': 'Cqbld123456.',
|
||||
'TrustServerCertificate': 'yes'
|
||||
}
|
||||
```
|
||||
|
||||
## Common Utilities
|
||||
|
||||
### `get_input_by_label(frame, label_text)`
|
||||
|
||||
Reference in New Issue
Block a user