Percy Appium Python Client

2.0.7 · active · verified Thu Apr 16

Percy Appium Python Client enables visual testing for mobile applications by integrating with Appium. It provides a function to take screenshots within your Appium tests and upload them to Percy for visual regression analysis. The library is actively maintained, with the latest stable version 2.0.7, and receives regular updates to support newer Appium and Python client versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an Appium driver and use `percy_screenshot` to capture visual snapshots. It assumes you have Appium and Percy CLI set up, and environment variables for Percy token and (optionally) BrowserStack credentials. Replace `<app_hash>` with your mobile application's identifier. The test should be executed via the `percy app:exec` command, which manages the Percy build lifecycle.

import os
from appium import webdriver
from percy import percy_screenshot

# Ensure PERCY_TOKEN is set in your environment
# export PERCY_TOKEN="your_percy_project_token"
# export BROWSERSTACK_USERNAME="your_bs_username"
# export BROWSERSTACK_ACCESS_KEY="your_bs_access_key"

PERCY_TOKEN = os.environ.get('PERCY_TOKEN', '')
BROWSERSTACK_USERNAME = os.environ.get('BROWSERSTACK_USERNAME', '')
BROWSERSTACK_ACCESS_KEY = os.environ.get('BROWSERSTACK_ACCESS_KEY', '')

if not PERCY_TOKEN:
    raise ValueError("PERCY_TOKEN environment variable is not set.")

desired_caps = {
    'app': 'bs://<app_hash>', # Replace with your app hash or local app path
    'deviceName': 'Google Pixel 3',
    'platformName': 'Android',
    'platformVersion': '9.0',
    'build': 'Percy Appium Python Build',
    'name': 'Percy Appium Test',
    'automationName': 'UiAutomator2'
}

# For BrowserStack App Automate
remote_url = f"https://{BROWSERSTACK_USERNAME}:{BROWSERSTACK_ACCESS_KEY}@hub-cloud.browserstack.com/wd/hub"

try:
    driver = webdriver.Remote(remote_url, desired_caps)
    # Your test steps here
    # ... navigate, interact ...

    percy_screenshot(driver, 'My First App Screenshot')

    # Example: Take another screenshot after an action
    # driver.find_element_by_accessibility_id('someElement').click()
    # percy_screenshot(driver, 'After Element Click')

finally:
    if driver:
        driver.quit()

# To run this test, you'll typically use the Percy CLI:
# PERCY_TOKEN=your_token percy app:exec -- python your_test_file.py

view raw JSON →