Playwright plugin for matching screenshots with Vedro Testing Framework
Project description
Vedro Screenshot Matcher
The screenshot_matcher (a.k.a. Machu Picchu) is a powerful tool designed for developers and testers to visually compare two versions of an application. By contrasting a production version (known as "golden") with a development version (referred to as "test"), spotting visual inconsistencies becomes more straightforward.
Integrated seamlessly with the vedro testing framework, it aids in performing visual regression tests with ease.
Installation
-
Install the Plugin
vedro plugin install vedro-screenshot-matcher -
Configure the Plugin In your
vedro.cfg.py:
import vedro
import screenshot_matcher
class Config(vedro.Config):
class Plugins(vedro.Config.Plugins):
class ScreenshotMatcher(screenshot_matcher.ScreenshotMatcher):
test_app_url = "http://localhost"
golden_app_url = "http://golden-app.com"
Make sure to provide the correct test_app_url and golden_app_url in the configuration.
Quick Start
Suppose you have a basic test as below:
import vedro
from contexts import opened_index_page
class Scenario(vedro.Scenario):
subject = "share page"
def given_opened_page(self):
self.page = opened_index_page()
def when_user_click_on_share(self):
self.page.get_by_text("Share").click()
def then_it_should_show_share_popup(self):
share_popup = self.page.locator(".share-popup .title")
assert share_popup.text_content() == "Share Page"
The context that opens the index page:
import vedro
import playwright
from os import environ
@vedro.context
async def opened_index_page():
browser = await playwright.chromium.launch()
page = await browser.new_page()
await page.goto(environ["APP_URL"])
return page
To implement a screenshot assertion:
- Add the
@screenshot_assertsdecorator at the beginning of the scenario - Include the
match_screenshotassertion where needed
import vedro
from screenshot_matcher import screenshot_asserts, match_screenshot
@screenshot_asserts() # Step 1: Add decorator
class Scenario(vedro.Scenario):
subject = "share page"
def given_opened_page(self):
self.page = opened_index_page()
def when_user_click_on_share(self):
self.page.get_by_text("Share").click()
def then_it_should_show_share_popup(self):
share_popup = self.page.locator(".share-popup .title")
assert share_popup.text_content() == "Share Page"
assert match_screenshot(share_popup) # Step 2: Add screenshot assertion
By following these steps, the plugin will:
- Execute the test using
APP_URLset to yourgolden_app_url - Capture a screenshot, storing it as the expected outcome
- Run the test again with
APP_URLset to yourtest_app_url - Finally, it will compare the new screenshot with the previously saved one
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file machu-picchu-0.1.0.tar.gz.
File metadata
- Download URL: machu-picchu-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdeee360b1e37fe3cb10170736dc75fa3b71b2e3e2b92b5333195fa28b229c86
|
|
| MD5 |
d30b820b75a54ebe72c8e5cc045606dd
|
|
| BLAKE2b-256 |
127d60e08d61c39ff5eecb86e5cba040672d2e8827cfb3477b72f78609d73a29
|
File details
Details for the file machu_picchu-0.1.0-py3-none-any.whl.
File metadata
- Download URL: machu_picchu-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac0baaea3bbd0597ab6dc7ca48bc0dea039f492bae2c460dbfb238eac39f76cf
|
|
| MD5 |
abfd0a12a109fe1f1c73ad96588c1dc4
|
|
| BLAKE2b-256 |
c4e45b493812cc6f8dc0d8a2e885ee37d0a7d132e887304abbba4289a6caa8d2
|