Applitools Eyes Core SDK Server (Python Client)
The `core-universal` package is part of the Applitools Eyes SDK ecosystem, serving as the Python client for the Eyes Core SDK Server. It provides the underlying communication protocol (using WebSockets) for Python SDKs (like `eyes-selenium`, `eyes-playwright`, `eyes-appium`) to interact with the Applitools Eyes service, where core functionality is implemented in JavaScript. End-users typically interact with higher-level Applitools SDKs rather than directly with `core-universal`. The current version is 4.16.5. Applitools SDKs are actively maintained with frequent releases.
Warnings
- gotcha Direct import and usage of `core-universal` is generally not intended for end-users. It serves as an internal communication layer for higher-level Applitools SDKs (e.g., `applitools.selenium`, `applitools.playwright`). Developers should use the appropriate specialized SDK for their testing framework.
- breaking Applitools Core Tools (which `core-universal` is a part of) version 4.8.0+ no longer supports Python 3.7 and 3.8. Attempting to use these Python versions with newer Core Tools may result in errors.
- gotcha The Applitools API Key (`APPLITOOLS_API_KEY`) is crucial for authenticating with the Applitools service. Forgetting to set it, or setting it incorrectly, will prevent tests from running or uploading results.
- gotcha Mutable default arguments in Python functions (e.g., `def func(arg=[]):`) can lead to unexpected shared state across function calls. While not specific to `core-universal`, this is a common Python footgun that can affect custom helper functions in test automation.
Install
-
pip install core-universal
Imports
- Eyes
from applitools.selenium import Eyes
- ClassicRunner
from applitools.selenium import ClassicRunner
- VisualGridRunner
from applitools.selenium import VisualGridRunner
Quickstart
import os
from selenium import webdriver
from applitools.selenium import Eyes, ClassicRunner, Target
def run_applitools_test():
# Set your Applitools API key from environment variable
# For a quickstart, ensure APPLITOOLS_API_KEY is set in your environment
api_key = os.environ.get('APPLITOOLS_API_KEY', 'YOUR_APPLITOOLS_API_KEY_HERE')
if not api_key or api_key == 'YOUR_APPLITOOLS_API_KEY_HERE':
print("Warning: APPLITOOLS_API_KEY environment variable not set. Test might fail.")
# In a real scenario, you'd raise an error or handle this more robustly
runner = ClassicRunner()
eyes = Eyes(runner)
eyes.api_key = api_key
# Configure Eyes to log to console for debugging
eyes.log_handler = None # Set to StreamMessageLogger() for console output
driver = None
try:
# Initialize a headless Chrome browser (ensure chromedriver is in PATH)
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
# Start the Applitools Eyes test
driver = eyes.open(driver=driver, app_name='My Python App', test_name='Simple Login Test', viewport_size={'width': 800, 'height': 600})
# Navigate to a URL and perform visual checkpoints
driver.get('https://demo.applitools.com')
eyes.check('Login Page', Target.window().fully())
# Perform some actions (e.g., filling a form, clicking buttons)
# For this example, just navigate to another page
driver.find_element_by_id('log-in').click()
eyes.check('App Page', Target.window().fully())
# Close the Eyes test and get results
results = eyes.close(raise_exception=True)
print(f"Applitools Test Results: {results}")
except Exception as e:
print(f"Applitools test failed: {e}")
finally:
if driver:
driver.quit()
# Always abort the test if it's open, even if an exception occurred
eyes.abort_if_not_closed()
if __name__ == '__main__':
run_applitools_test()