Applitools Eyes SDK for Python (Common Code)
Applitools `eyes-common` is the foundational, common code package for the Applitools Eyes Python SDK. It provides core functionalities for visual testing that are leveraged by specific integration packages like `eyes-selenium`, `eyes-playwright`, and `eyes-appium`. The library is actively maintained, with frequent updates to its dependent SDKs, reflecting a continuous release cadence. The current version on PyPI is 6.7.2.
Warnings
- breaking Migration from Applitools Eyes Python SDK v3 to v4 (specifically for `eyes-selenium`) introduced significant API changes, moving from a 'Classic API' (e.g., `check_window()`) to a 'Fluent API' (`check()`). Users migrating older tests will need to update their checkpoint calls.
- gotcha Failing to set the `APPLITOOLS_API_KEY` environment variable will prevent tests from running and uploading results to the Applitools Test Manager. The SDK requires this key for authentication.
- gotcha Not calling `eyes.close()` at the end of a test (e.g., due to an unhandled exception) can result in tests being marked as 'Aborted' in the Applitools Test Manager and test results not being finalized or reported correctly.
- gotcha `eyes-common` is a shared dependency. Users should install and use the specific Applitools Eyes SDK for their testing framework (e.g., `eyes-selenium` for Selenium, `eyes-playwright` for Playwright, `eyes-appium` for Appium). Directly importing from `eyes-common` for core functionality is generally not the intended pattern, though some common utilities might be exposed.
- gotcha When using `VisualGridRunner` for the Ultrafast Grid, concurrency might be limited to 1 for free Applitools accounts, which can affect the parallel execution benefits.
Install
-
pip install eyes-selenium -
pip install eyes-playwright -
pip install eyes-appium
Imports
- Eyes
from applitools.selenium import Eyes
- Configuration
from applitools.selenium import Configuration
- BatchInfo
from applitools.common.batch_info import BatchInfo
- Target
from applitools.selenium import Target
- ClassicRunner
from applitools.selenium import ClassicRunner
- VisualGridRunner
from applitools.selenium import VisualGridRunner
Quickstart
import os
from selenium import webdriver
from applitools.selenium import Eyes, Target, Configuration, ClassicRunner
from applitools.common.batch_info import BatchInfo
# Set your Applitools API key as an environment variable APPLITOOLS_API_KEY
# For example: export APPLITOOLS_API_KEY='YOUR_API_KEY'
APPLITOOLS_API_KEY = os.environ.get('APPLITOOLS_API_KEY', '')
if not APPLITOOLS_API_KEY:
raise ValueError("APPLITOOLS_API_KEY environment variable not set.")
runner = ClassicRunner()
eyes = Eyes(runner)
config = Configuration()
config.set_api_key(APPLITOOLS_API_KEY)
config.set_app_name('Hello World App')
config.set_test_name('My First Visual Test')
config.set_batch(BatchInfo('Python Quickstart Batch'))
eyes.set_configuration(config)
driver = None
try:
# Initialize a Chrome WebDriver (ensure you have chromedriver installed and in PATH)
driver = webdriver.Chrome()
# Navigate to a URL
driver.get('https://applitools.com/helloworld')
# Start the visual test
eyes.open(driver)
# Visual checkpoint #1.
eyes.check('Hello World Page', Target.window())
# Click a button to change content (example for a second checkpoint)
# driver.find_element_by_css_selector('button').click()
# eyes.check('Hello World Page after click', Target.window())
# End the test
eyes.close(raise_exception=True)
finally:
# Close the browser
if driver:
driver.quit()
# Close the Eyes runner if it's still open (e.g., due to an aborted test)
runner.get_all_test_results(raise_exception=True)
print("Visual test completed. Check Applitools Test Manager for results.")