Applitools Eyes SDK for Selenium Python

6.4.32 · active · verified Mon Apr 13

Applitools Eyes SDK for Selenium Python is a proxy package that facilitates automated visual testing for web applications by integrating with Selenium WebDriver. It allows developers and QA engineers to automatically validate the correctness of an application's UI layout, content, and appearance using AI-driven image comparisons. The current version is 6.4.32, and the library is actively maintained with frequent patch releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic visual test using `eyes-selenium` with `pytest` and Selenium WebDriver. It initializes a `VisualGridRunner` for efficient test management, sets the Applitools API key, and performs visual checkpoints on a web page. The `APPLITOOLS_API_KEY` must be set as an environment variable. The example includes navigating to a demo site, logging in, and performing visual checks on both the login and dashboard pages.

import os
import pytest
from selenium import webdriver
from applitools.selenium import Eyes, Target, VisualGridRunner, 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.")

@pytest.fixture(scope='session')
def applitools_runner():
    runner = VisualGridRunner()
    yield runner
    # Wait for all visual tests to complete and get results
    print("\nVisual test results:\n", runner.get_all_test_results(raise_exception=True))

@pytest.fixture(scope='function')
def driver():
    # Ensure your ChromeDriver version matches your Chrome browser version
    options = webdriver.ChromeOptions()
    # options.add_argument('--headless') # Uncomment for headless execution
    driver = webdriver.Chrome(options=options)
    driver.implicitly_wait(10)
    yield driver
    driver.quit()

def test_applitools_example(driver, applitools_runner):
    eyes = Eyes(runner=applitools_runner)
    eyes.api_key = APPLITOOLS_API_KEY
    eyes.batch = BatchInfo('My Python App') # Group tests in Test Manager
    
    try:
        # Open Eyes with the WebDriver, application name, test name, and viewport size
        eyes.open(driver=driver, app_name='My App', test_name='Login Page Test', viewport_size={'width': 800, 'height': 600})
        
        driver.get('https://demo.applitools.com/')
        eyes.check('Login Window', Target.window().fully())
        
        driver.find_element('id', 'username').send_keys('user')
        driver.find_element('id', 'password').send_keys('password')
        driver.find_element('id', 'log-in').click()
        
        eyes.check('App Dashboard', Target.window().fully())
        
    finally:
        # Close Eyes to finish the test session
        eyes.close()

view raw JSON →