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.
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.

