Hers is How You Can Integrate Percy with Selenium Python Tests

Step by step tutorial to Integrate Percy with Selenium Python Tests


Setup @percy/cli (currently only available from NPM). This package handles all of the processing and interactions with Percy's API:

npm install --save-dev @percy/cli

 

Install the Python package for Percy-Selenium:

pip install percy-selenium

 

Step 1: Import the percy snapshot function from the percy_selenium package into your test in order to begin taking snapshots of your Selenium tests.

# At the top of your test file(s)

from percy import percy_snapshot



Step 2: You can now add visual tests to your current testing framework:

from selenium import webdriver

from percy import percy_snapshot


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

browser.implicitly_wait(10)


new_todo_input = browser.find_element_by_class_name('new-todo')

percy_snapshot(browser, 'Empty Todo State')


Step 3: Lastly, use the percy exec command to enclose your test runner command. In order to receive snapshots from your Python Selenium tests, this will launch a local Percy server. Following processing, the snapshots are then uploaded to your Percy dashboard. Percy exec -- python tests.py might be used as an illustration.



Percy needs the PERCY TOKEN environment variable specified before it can be effectively launched:


export PERCY_TOKEN=[your-projects-token]



Now you should be able to run percy exec. For example:

percy exec -- python tests.py

 

Remember to include a double-dash, --, between your test run command and percy exec.

Done! Now, everytime you execute a test with Percy, Percy will upload a snapshot of the app in that state for visual regression testing!


Comments