Percy Developer Hub

Welcome to the Percy Developer Hub. You'll find comprehensive guides and documentation to help you start working with Percy as quickly as possible, as well as support if you get stuck. Let's jump right in!

Selenium for Python

Integrating Percy with your Selenium Python tests

Covered in this doc

Integrating Percy with your Selenium Python tests
Installing and importing the percy-python-selenium module
Calling and configuring percySnapshot

percy-python-selenium on GitHub

CircleCI This project is using Percy.io for visual regression testing.

Setup


If you're not ready to integrate Percy, check out our 2-minute Python Selenium tutorial and example app with Percy already added.

Install @percy/agent. This package does the heavy lifting & communication to our API:

npm install --save-dev @percy/agent
yarn add -D @percy/agent

Now install the percy-python-selenium package:

pip install percy-python-selenium

Step 1: In order to start creating snapshots from your Selenium tests, you'll need to import the percy-python-selenium package into your test.

# At the top of your test file(s)
from percy import percySnapshot

Step 2: You can now incorporate visual tests in your existing suite:

from selenium import webdriver
from percy import percySnapshot

browser.get('http://localhost:8000')
browser.implicitly_wait(10)

newTodoInput = browser.find_element_by_class_name('new-todo')
percySnapshot(browser=browser, name='Empty Todo State')

```

Step 3: Finally, wrap your test runner command in the percy exec command. This will start a Percy agent to receive snapshots from your Python Selenium tests and upload them to your Percy dashboard. An example might be: percy exec -- python tests.py.

Before you can successfully run Percy, the PERCY_TOKEN environment variable must be set:

export PERCY_TOKEN=[your-projects-token]
set PERCY_TOKEN=[your-projects-token]

Now you can run percy exec. For example:

percy exec -- python tests.py

Note the double dash, --, between percy exec and your test run command.

That's it! Now, whenever you run your tests with Percy, a snapshot of the app in that state will be uploaded to Percy for visual regression testing!

Configuration


percySnapshot(browser, snapshotName);
percySnapshot(browser, snapshotName, **options);

browser is the Selenium webdriver browser instance
snapshotName is a required string that will be used as the snapshot name.
options is are optional arguments that can include:

  • widths: An array of integers representing the browser widths at which you want to take snapshots.
  • minHeight: An integer specifying the minimum height of the resulting snapshot, in pixels. Defaults to 1024px.
  • percyCSS: A string containing Percy specific CSS that will be applied to this snapshot.
  • requestHeaders: An object containing HTTP headers to be sent for each request made during asset discovery for this snapshot.
  • enableJavaScript: A boolean to enable JavaScript execution in our rendering environment. Defaults to false.

For example:

percySnapshot(browser=driver, name='Home page');
percySnapshot(browser=driver, name='Homepage responsive test', widths=[768, 992, 1200]);
percySnapshot(browser=driver, name='Homepage responsive test', percyCSS="iframe { display: none; }");

Global configuration

You can also configure Percy to use the same options over all snapshots. To see supported configuration including widths read our SDK configuration docs

Updated about a month ago

Selenium for Python


Integrating Percy with your Selenium Python tests

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.