Applitools Eyes SDK for Python (Common Code)

6.7.2 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates a basic visual test using `eyes-selenium` to integrate with Selenium WebDriver. It initializes Applitools Eyes, navigates to a webpage, performs a visual checkpoint, and then closes the test. The `APPLITOOLS_API_KEY` must be set as an environment variable for authentication. It also correctly handles the `runner` and `eyes` object lifecycle.

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

view raw JSON →