Skip to main content

Selenium Teleport: Reuse Login State Without Losing Test Coverage

Avoid repeated login setup where the application permits it, and verify the restored identity before continuing.

2 min read
Selenium Teleport: Reuse Login State Without Losing Test Coverage
On this page

Release checked September 5, 2026
This article now reflects v2.1.1 and the documented behavior of that project. Existing URLs are preserved so older links continue to work.

Repeating a full login flow in every feature test increases setup time and gives unrelated failures another place to occur. Saving and restoring state can help when the application accepts that state. It should be a deliberate fixture strategy, not a promise to skip authentication forever.

Restore only what the library captures

Selenium Teleport saves current-origin cookies, localStorage, and sessionStorage. IndexedDB support is diagnostic metadata only; database records are not restored. Server-side session expiry, device binding, revocation, or multi-origin authentication can still require a new login.

Navigate, restore, and verify

The library validates the saved origin, navigates to the destination origin, injects supported state, then opens the requested URL. Your fixture must still prove that the expected account and permissions are active.

python
from selenium_teleport import Teleport, create_driver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Supply TELEPORT_ENCRYPTION_KEY securely before running.
driver = create_driver()
try:
    with Teleport(driver, 'session.enc', encrypt=True, auto_save=False) as session:
        if session.has_state():
            session.load('https://test.example.com/dashboard')
        else:
            driver.get('https://test.example.com/login')
            # Complete your application's approved login flow here.
        WebDriverWait(driver, 30).until(
            EC.visibility_of_element_located((By.ID, 'account-menu'))
        )
        session.save()  # Explicit save lets failures reach the caller.
finally:
    driver.quit()

Protect both the state and its lifecycle

  • Use a dedicated test account and encrypted state.
  • Keep the encryption key separate from the state file.
  • Create isolated state per account or worker when tests mutate it.
  • Handle expiry and failed restoration explicitly.
  • Revoke exposed sessions and remove expired artifacts according to your retention policy.

Stealth integration is optional

The base driver uses regular Selenium. Optional sb-stealth-wrapper integration has separate load_state_stealth and save_state_stealth helpers. It does not guarantee that a site will accept automated traffic or bypass its access controls.

Measure setup savings honestly

Compare equivalent runs with the same browser, account, network, and application revision. Record authentication failures as well as runtime. The earlier fixed “10 seconds versus 0.5 seconds” claim was not a general benchmark and has been removed.

Keep direct login tests in the suite. Use state reuse for feature tests that need an authenticated starting point, then independently assert the feature outcome. Read the 2.1.1 security review for exact restoration boundaries.

Current project documentation

Dhiraj Das

About the Author

Dhiraj Das is an Automation Consultant with over a decade of experience building systems that expose failures, reduce flakiness, and make complex workflows repeatable. He applies that discipline to AI-agent validation, LLM testing, and postmortems.

He shares small open source utilities from real automation work, including: waitless (flaky tests), sb-stealth-wrapper (bot detection), selenium-teleport (state persistence), selenium-chatbot-test (AI chatbot testing), lumos-shadowdom (Shadow DOM), and visual-guard (visual regression).

Share this article: