Automatically refresh Selenium Chrome tabs at specified intervals
Project description
Selenium Auto Refresh
Automatically refresh Selenium Chrome tabs at specified intervals. Perfect for keeping sessions alive during long-running automation tasks.
Features
- 🔄 Automatic page refresh at customizable intervals
- 🛡️ Error handling for failed refreshes
- 🎯 Compatible with all Selenium-based drivers
- 🔧 Context manager support
- 📊 Runtime interval changes
- 🪶 Lightweight with no dependencies
Installation
pip install selenium-auto-refresh
Quick Start
from selenium import webdriver
from selenium_auto_refresh import ChromeRefresher
# Setup your driver
driver = webdriver.Chrome()
driver.get("https://example.com")
# Start auto-refresh every 60 seconds
refresher = ChromeRefresher(driver, interval=60)
refresher.start()
# Your automation code here...
time.sleep(300) # Run for 5 minutes
# Stop auto-refresh
refresher.stop()
driver.quit()
Context Manager Usage
with ChromeRefresher(driver, interval=30) as refresher:
# Auto-refresh starts automatically
# Your automation code here...
pass
# Auto-refresh stops automatically
Compatible Drivers
- ✅ Selenium WebDriver
- ✅ SeleniumBase Driver
- ✅ undetected-chromedriver
- ✅ Any driver with
.refresh()method
API Reference
ChromeRefresher(driver, interval=60)
Parameters:
driver: WebDriver instance with.refresh()methodinterval: Refresh interval in seconds (default: 60)
Methods:
start(): Start auto-refreshstop(): Stop auto-refreshis_running(): Check if runningchange_interval(seconds): Change refresh interval
License
MIT License
## 5. Create tests:
```python:tests/test_refresher.py
import unittest
from unittest.mock import Mock, patch
import time
from selenium_auto_refresh import ChromeRefresher
class TestChromeRefresher(unittest.TestCase):
def setUp(self):
self.mock_driver = Mock()
self.mock_driver.refresh = Mock()
def test_init_valid_driver(self):
refresher = ChromeRefresher(self.mock_driver, 30)
self.assertEqual(refresher.interval, 30)
self.assertFalse(refresher.running)
def test_init_invalid_driver(self):
invalid_driver = Mock()
del invalid_driver.refresh
with self.assertRaises(AttributeError):
ChromeRefresher(invalid_driver)
def test_init_invalid_interval(self):
with self.assertRaises(ValueError):
ChromeRefresher(self.mock_driver, -1)
def test_start_stop(self):
refresher = ChromeRefresher(self.mock_driver, 1)
refresher.start()
self.assertTrue(refresher.is_running())
refresher.stop()
self.assertFalse(refresher.is_running())
def test_context_manager(self):
with ChromeRefresher(self.mock_driver, 1) as refresher:
self.assertTrue(refresher.is_running())
self.assertFalse(refresher.is_running())
if __name__ == '__main__':
unittest.main()
6. Publish to PyPI:
# Install build tools
pip install build twine
# Build the package
python -m build
# Upload to PyPI (test first)
twine upload --repository testpypi dist/*
# Upload to PyPI (production)
twine upload dist/*
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 selenium_auto_refresh-1.1.0.tar.gz.
File metadata
- Download URL: selenium_auto_refresh-1.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1691decbbfa4cfe5335b99eaca8892361d775b992bde82e80248ae8a2d229bf7
|
|
| MD5 |
4fb0a1d0712474061bcf9dcc5b6e580a
|
|
| BLAKE2b-256 |
6634bd05b29c3cf3208347ea92dafb585bfa2c8b0a4a90d873302077d01d2632
|
File details
Details for the file selenium_auto_refresh-1.1.0-py3-none-any.whl.
File metadata
- Download URL: selenium_auto_refresh-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e4648b21cc007949bc512d6c012dfaed31385a48c3a7cb1cfcda9a9c8e6694d
|
|
| MD5 |
b04e42889d5a50be6b428021dfdb6a1b
|
|
| BLAKE2b-256 |
1103dfefc2000b818b300b6f13377afcdefd873c8518bb2c1e1716258d9ba9c7
|