Percy Selenium Python

raw JSON →
2.1.4 verified Fri May 01 auth: no python

Python client for visual testing with Percy. Integrates with Selenium to capture screenshots and perform visual regression testing via Percy's cloud service. Current version 2.1.4, supports Python >=3.6, and is maintained by BrowserStack.

pip install percy-selenium
error ModuleNotFoundError: No module named 'percy'
cause Trying to import the old 'percy' module after upgrading to v2.0+.
fix
Install/upgrade: pip install --upgrade percy-selenium and use from percy_selenium import Percy.
error Exception: Percy is not running
cause The Percy CLI or service is not started; or PERCY_TOKEN is missing.
fix
Ensure the Percy CLI is running (percy exec -- ...) or set PERCY_TOKEN environment variable. If running locally, start Percy: percy exec -- <your test command>.
error AttributeError: 'Percy' object has no attribute 'snapshot'
cause Using an older version (<2.0) where the method name was different or the class structure was incompatible.
fix
Upgrade to >=2.0 and use percy.snapshot('name'). Check the import is from percy_selenium import Percy.
breaking In v2.0.0, the import path changed from `percy` to `percy_selenium`. Old imports (`from percy import Percy`) will break. Additionally, the `Percy` class no longer supports `desired_capabilities`; use `webdriver.Options` instead.
fix Update imports to `from percy_selenium import Percy`. Replace `desired_capabilities` with `options`.
gotcha The `PERCY_TOKEN` environment variable must be set for snapshot uploads. If missing, snapshots are silently skipped.
fix Set `PERCY_TOKEN` to your project's token from the Percy dashboard.
gotcha The `snapshot()` method is asynchronous by default; snapshots are queued and processed after the test. To wait for upload, use `snapshot(name, wait=True)` or call `percy.flush()`.
fix Use `percy.snapshot('name', wait=True)` or call `percy.flush()` after all snapshots.

Captures a visual snapshot of the current page using the Percy SDK.

from selenium import webdriver
from percy_selenium import Percy

# Initialize Percy with driver
driver = webdriver.Chrome()
percy = Percy(driver)

# Navigate and snapshot
driver.get('https://example.com')
percy.snapshot('Homepage')