Hey! These docs are for version 1, which is no longer officially supported. Click here for the latest version, 2-web!


### [python-percy-client on Github](🔗)

[![Package Status](https://img.shields.io/pypi/v/percy.svg)](🔗) [![Build Status](https://travis-ci.org/percy/python-percy-client.svg?branch=master)](🔗)

Python client library for visual regression testing with [Percy](🔗) and Selenium tests.

This library is in beta---we welcome contributions to improve it.

# Installation



Make sure you have completed [Setup](🔗) of your CI service first. You can also test Percy in your [local development](🔗) environment.

Requires Python >= 2.7.



# Setup




The following assumes that `webdriver` is a Selenium webdriver object of some sort (like `webdriver.Chrome()`). Proper setup and teardown of Selenium tests is not included here.

First, create a `ResourceLoader` object. This is the configuration for how Percy will discover your app's assets.



Now, create a `percy.Runner` object and initialize a build. This must be done at the beginning of your entire test suite.



Then, at the end of your entire test suite, finalize the build (this needs to be run even if tests fail):



# Usage




During Selenium tests, use `percy_runner.snapshot()` in any test to capture the DOM state and send it to Percy for rendering and visual regression testing.



`snapshot` also accepts a `name` to uniquely identify it across builds:



Done! Now commit and push your branch to run your tests in your CI service, or create a GitHub PR.

## Responsive testing

Setup default responsive breakpoints for all snapshots:



These are the default responsive widths to be used on every snapshot. They can be overridden on a per-snapshot basis by passing the `widths` arg to `snapshot()`.

# Troubleshooting




To temporarily disable Percy in CI, set the `PERCY_ENABLE=0` environment variable.

See [Percy usage in the Sentry repository](🔗) for a complete example of Percy integrated in a large Django application and with `pytest`integration.

# Contributing



  1. Fork it ( <https://github.com/percy/python-percy-client/fork> )

  2. Create your feature branch (`git checkout -b my-new-feature`)

  3. Commit your changes (`git commit -am 'Add some feature'`)

  4. Push to the branch (`git push origin my-new-feature`)

  5. Create a new Pull Request

[Throw a ★ on it!](🔗)