A robust and extensible Chrome browser automation tool
Project description
Chrome Puppet
Automate Chrome with confidence - A robust, production-ready browser automation framework
Chrome Puppet is a Python framework that makes browser automation simple and reliable. Built on top of Selenium, it provides a clean, intuitive API for automating Chrome/Chromium browsers with built-in best practices for stability and maintainability.
โจ Features
- Modern API: Intuitive Python interface for browser control
- Cross-Platform: Works on Windows, macOS, and Linux
- Robust Error Handling: Comprehensive error handling and recovery
- Automatic ChromeDriver Management: No need to manually manage ChromeDriver versions
- Headless Mode: Run browsers in headless mode for CI/CD pipelines
- Extensible: Easy to extend with custom functionality
๐ Quick Start
Prerequisites
- Python 3.8+
- Chrome/Chromium browser
Installation
# Install from PyPI
pip install chrome-puppet
# Or install from source
git clone https://github.com/consumrbuzzy/chrome-puppet.git
cd chrome-puppet
pip install -e .
Basic Usage
from chrome_puppet import ChromePuppet
# Create a browser instance and navigate to a page
with ChromePuppet() as browser:
browser.get("https://example.com")
print(f"Page title: {browser.title}")
For more detailed examples, see EXAMPLES.md.
๐ Project Structure
chrome-puppet/
โโโ core/ # Core browser automation code
โ โโโ __init__.py
โ โโโ browser/ # Browser implementation
โ โ โโโ __init__.py
โ โ โโโ base.py # Base browser class
โ โ โโโ chrome.py # Chrome implementation
โ โ โโโ element.py # Element interactions
โ โ โโโ exceptions.py # Custom exceptions
โ โ โโโ navigation.py # Navigation utilities
โ โ โโโ screenshot.py # Screenshot functionality
โ โโโ config.py # Configuration management
โ โโโ utils/ # Utility functions
โโโ tests/ # Test suite
โ โโโ __init__.py
โ โโโ base_test.py # Base test class
โ โโโ conftest.py # Pytest configuration
โ โโโ test_data/ # Test data files
โ โโโ test_browser.py # Browser automation tests
โโโ examples/ # Example scripts
โ โโโ browser_example.py # Example usage
โโโ .gitignore
โโโ CHANGELOG.md
โโโ EXAMPLES.md
โโโ LICENSE
โโโ pyproject.toml
โโโ README.md
โโโ requirements.txt # Runtime dependencies
โโโ requirements-dev.txt # Development dependencies
๐ Documentation
- Examples - Comprehensive examples and usage patterns
- API Reference - Detailed API documentation (coming soon)
- Contributing Guidelines - How to contribute to the project
๐งช Running Tests
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest tests/
# Run with coverage report
pytest --cov=core tests/
๐ค Contributing
Contributions are welcome! Please read our Contributing Guidelines for details on how to submit pull requests.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ฆ Installation
-
Clone the repository:
git clone https://github.com/yourusername/chrome-puppet.git cd chrome-puppet
-
Set up a virtual environment (recommended):
python -m venv venv # On Windows: .\venv\Scripts\Activate.ps1 # On macOS/Linux: # source venv/bin/activate
-
Install dependencies:
pip install -e .
For development:
pip install -r requirements-dev.txt
macOS/Linux
# Create virtual environment
python3 -m venv .venv
# Activate the virtual environment
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# For development
pip install -r requirements-dev.txt
Using the Virtual Environment
- To activate the virtual environment, run the appropriate command above
- Your command prompt should show
(.venv)at the beginning when activated - To deactivate, simply type
deactivate - Always activate the virtual environment before running the project
Environment Variables
Create a .env file in the project root based on .env.example:
# Chrome settings
CHROME_HEADLESS=false
CHROME_WINDOW_SIZE=1920,1080
CHROME_IMPLICIT_WAIT=10
# Logging
LOG_LEVEL=INFO
LOG_FILE=chrome_puppet.log
# Browser settings
CHROME_PATH=auto # Set to 'auto' for auto-detection or specify path
CHROME_VERSION_OVERRIDE= # Leave empty for auto-detection
Quick Start
Basic Usage
from chrome_puppet import ChromePuppet
# Initialize Chrome Puppet (runs in headless mode by default)
with ChromePuppet() as browser:
# Navigate to a website
browser.get("https://www.example.com")
# Get page title
print(f"Page title: {browser.title}")
# Take a screenshot (saved to screenshots/ directory)
screenshot_path = browser.take_screenshot("example_page")
print(f"Screenshot saved to: {screenshot_path}")
Advanced Configuration
from chrome_puppet import ChromePuppet, ChromeConfig
# Create a custom configuration
config = ChromeConfig(
headless=False, # Run in visible mode
window_size=(1366, 768),
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
download_dir="path/to/downloads",
implicit_wait=10, # seconds
verbose=True # Enable debug logging
)
# Use the custom configuration
with ChromePuppet(config=config) as browser:
browser.get("https://www.example.com")
print(f"Current URL: {browser.driver.current_url}")
Configuration
The ChromeConfig class allows you to customize the browser behavior:
config = ChromeConfig(
headless=True, # Run in headless mode
window_size=(1920, 1080), # Browser window size
user_agent="Custom User Agent String",
timeout=30, # Default timeout in seconds
chrome_type=ChromeType.GOOGLE, # Or ChromeType.CHROMIUM
download_dir="./downloads", # Custom download directory
chrome_arguments=[
"--disable-notifications",
"--disable-infobars"
]
)
Examples
Basic Usage
from chrome_puppet import ChromePuppet
with ChromePuppet() as browser:
browser.get("https://quotes.toscrape.com/")
soup = browser.get_soup()
quotes = soup.find_all('div', class_='quote')
for quote in quotes:
print(quote.find('span', class_='text').text)
Handling Dynamic Content
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
with ChromePuppet() as browser:
browser.get("https://example.com/dynamic")
# Wait for an element to be present
element = WebDriverWait(browser.driver, 10).until(
EC.presence_of_element_located((By.ID, "dynamic-element"))
)
# Interact with the element
element.click()
Project Structure
stable_chrome_puppet/
โโโ __init__.py # Package initialization
โโโ chrome.py # Main Chrome browser implementation
โโโ config.py # Configuration classes
โโโ utils.py # Utility functions
โโโ example.py # Example usage
โโโ requirements.txt # Project dependencies
โโโ README.md # This file
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chrome_puppet-0.1.0.tar.gz.
File metadata
- Download URL: chrome_puppet-0.1.0.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3055130d94fd3f49a18808db899a4f8259c2d761137c36940c9a06ae9fc308c
|
|
| MD5 |
3952343394bc5668e5e14f5a60d76630
|
|
| BLAKE2b-256 |
5e0be7d888a0f64586443407060b82d81d12216567fb5e77fcef9df6c7a6b560
|
File details
Details for the file chrome_puppet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chrome_puppet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 42.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17af55e711a1a51d060df992990892bf5974febf06ae25dd405e1b47afcaa439
|
|
| MD5 |
7e6a436999c74a430f3330f1b62c428e
|
|
| BLAKE2b-256 |
b4c823cee3be5df0161aae8523e359c4f4117438109c400c9f9c83933e5227f4
|