Open source, self hosted solution for visual testing and managing results of visual testing.
Project description
Python SDK for Visual Regression Tracker
Install
pip install visual-regression-tracker
# or, with playwright integration
pip install visual-regression-tracker[playwright]
python -m playwright install
Usage
Import
from visual_regression_tracker import VisualRegressionTracker, Config, TestRun
Configure connection
config = Config(
# apiUrl - URL where backend is running
apiUrl='http://localhost:4200',
# project - Project name or ID
project='Default project',
# apiKey - User apiKey
apiKey='tXZVHX0EA4YQM1MGDD',
# ciBuildId - Current git commit SHA
ciBuildId='commit_sha',
# branch - Current git branch
branchName='develop',
# enableSoftAssert - Log errors instead of exceptions
enableSoftAssert=False,
)
vrt = VisualRegressionTracker(config)
Setup / Teardown
As context manager:
with vrt:
...
# track test runs
...
Without context manager:
vrt.start()
...
# track test runs
...
vrt.stop()
Assert
vrt.track(TestRun(
# Name to be displayed
# Required
name='Image name',
# Base64 encoded string
# Required
imageBase64=image,
# Allowed mismatch tollerance in %
# Optional
# Default: 0%
diffTollerancePercent=1,
# Optional
os='Mac',
# Optional
browser='Chrome',
# Optional
viewport='800x600',
# Optional
device='PC',
# Array of areas to be ignored
ignoreAreas=[
IgnoreArea(
# X-coordinate relative of left upper corner
# Required
x=10,
# Y-coordinate relative of left upper corner
# Required
y=20,
# Area width in px
# Required
width=300,
# Height width in px
# Required
height=400
)
],
))
Integration with Microsoft Playwright
Imports
from playwright import sync_playwright
from visual_regression_tracker import Config, TestRun
from visual_regression_tracker.p import PlaywrightVisualRegressionTracker
Start playwright and navigate to page
playwright = sync_playwright().start()
browserType = playwright.chromium
browser = browserType.launch(headless=False)
page = browser.newPage()
page.goto('https://www.python.org/')
Configure connection to VRT server
config = Config(
# apiUrl - URL where backend is running
apiUrl='http://localhost:4200',
# project - Project name or ID
project='Default project',
# apiKey - User apiKey
apiKey='tXZVHX0EA4YQM1MGDD',
# ciBuildId - Current git commit SHA
ciBuildId='commit_sha',
# branch - Current git branch
branchName='develop',
# enableSoftAssert - Log errors instead of exceptions
enableSoftAssert=False,
)
vrt = PlaywrightVisualRegressionTracker(config, browserType)
Setup / Tear down
As context manager:
with vrt:
...
# track test runs
...
Without context manager:
vrt.start()
...
# track test runs
...
vrt.stop()
Track page
vrt.trackPage(page, imageName[, options])
-
page: Page
Playwright page -
imageName: str
name for the taken screenshot image -
options: PageTrackOptions
optional configuration with:-
diffTollerancePercent: float
specify acceptable difference from baseline, between0-100
. -
ignoreAreas: List[IgnoreArea]
x: int
X-coordinate relative of left upper cornery: int
Y-coordinate relative of left upper cornerwidth: int
area width in pxheight: int
area height in px
-
screenshotOptions: PageScreenshotOptions
configuration for Playwrightsscreenshot
method-
fullPage: bool
When true, takes a screenshot of the full scrollable page, instead of the currently visibvle viewport. Defaults tofalse
. -
omitBackground: bool
Hides default white background and allows capturing screenshots with transparency. Defaults tofalse
. -
clip: FloatRect
An object which specifies clipping of the resulting image. Should have the following fields:x: float
x-coordinate of top-left corner of clip areay: float
y-coordinate of top-left corner of clip areawidth: float
width of clipping areaheight: float
height of clipping area
-
timeout: float
Maximum time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
-
-
agent: Agent
Additional information to mark baseline across agents that have different:os: str
operating system name, like Windows, Mac, etc.device: str
device name, PC identifier, mobile identifier etc.viewport: str
viewport size.
-
Track element handle
vrt.trackElementHandle(elementHandle, imageName[, options])
-
elementHandle: ElementHandle
Playwright ElementHandle -
imageName: str
name for the taken screenshot image -
options: ElementHandleTrackOptions
optional configuration with:-
diffTollerancePercent: float
specify acceptable difference from baseline, between0-100
. -
ignoreAreas: List[IgnoreArea]
x: int
X-coordinate relative of left upper cornery: int
Y-coordinate relative of left upper cornerwidth: int
area width in pxheight: int
area height in px
-
screenshotOptions: ElementHandleScreenshotOptions
configuration for Playwrightsscreenshot
method-
omitBackground: bool
Hides default white background and allows capturing screenshots with transparency. Defaults tofalse
. -
timeout: float
Maximum time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
-
-
agent: Agent
Additional information to mark baseline across agents that have different:os: str
operating system name, like Windows, Mac, etc.device: str
device name, PC identifier, mobile identifier etc.viewport: str
viewport size.
-
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
File details
Details for the file visual_regression_tracker-4.6.0.tar.gz
.
File metadata
- Download URL: visual_regression_tracker-4.6.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33a80c4ec94dcd20bd0e4c458a2ee4500f41553282f2d916679064cd216e6bb9 |
|
MD5 | 3fd854b496f1ec4fcbf966560346414b |
|
BLAKE2b-256 | fd0cd3bcb216b314aad6642f6de9b05a54aa90cd7eba736064ab68a456f93a72 |
Provenance
File details
Details for the file visual_regression_tracker-4.6.0-py2.py3-none-any.whl
.
File metadata
- Download URL: visual_regression_tracker-4.6.0-py2.py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb1c40ef6179096923c3df48ff241de6fd90d886ce574fad14da181294a4ce0 |
|
MD5 | 2e0dce1cf2de30efbd7f731d870538bd |
|
BLAKE2b-256 | 34dcabe2df88be209f784a78be55a7a9f01f5784f0bfc19c9846adfc4828edb5 |