Skip to main content

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() method
  • interval: Refresh interval in seconds (default: 60)

Methods:

  • start(): Start auto-refresh
  • stop(): Stop auto-refresh
  • is_running(): Check if running
  • change_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selenium_auto_refresh-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

selenium_auto_refresh-1.0.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file selenium_auto_refresh-1.0.0.tar.gz.

File metadata

  • Download URL: selenium_auto_refresh-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for selenium_auto_refresh-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fe57815e7285ea9d69259590d682480af59653931fb6727c1792b325ec4bf068
MD5 246efbda79df6a893908541edf9b4480
BLAKE2b-256 b6a3dce86b2c2b7270d598914398cbae4114dab3f34c13a19414be9aa3e5c596

See more details on using hashes here.

File details

Details for the file selenium_auto_refresh-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for selenium_auto_refresh-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b41d1164ed7ef3fbd32298d98250bbffb3f29de22558e30935f976c8cb9209b4
MD5 ce3949928ac012219dc4b2f6d6ea2a1f
BLAKE2b-256 a932b0a9014e162ec5c331090c1a0d5f4893b0e5d15c019a486b0d25b85b8e73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page