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
As python
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)
Or, as JSON config file vrt.json
{
"apiUrl":"http://localhost:4200",
"project":"Default project",
"apiKey":"tXZVHX0EA4YQM1MGDD",
"ciBuildId":"commit_sha",
"branchName":"develop",
"enableSoftAssert":false
}
vrt = VisualRegressionTracker()
Or, as environment variables
VRT_APIURL="http://localhost:4200" \
VRT_PROJECT="Default project" \
VRT_APIKEY="tXZVHX0EA4YQM1MGDD" \
VRT_CIBUILDID="commit_sha" \
VRT_BRANCHNAME="develop" \
VRT_ENABLESOFTASSERT=true \
python
vrt = VisualRegressionTracker()
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
vrt = PlaywrightVisualRegressionTracker(browserType, config)
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: PagePlaywright page -
imageName: strname for the taken screenshot image -
options: PageTrackOptionsoptional configuration with:-
diffTollerancePercent: floatspecify acceptable difference from baseline, between0-100. -
ignoreAreas: List[IgnoreArea]x: intX-coordinate relative of left upper cornery: intY-coordinate relative of left upper cornerwidth: intarea width in pxheight: intarea height in px
-
screenshotOptions: PageScreenshotOptionsconfiguration for Playwrightsscreenshotmethod-
full_page: boolWhen true, takes a screenshot of the full scrollable page, instead of the currently visibvle viewport. Defaults tofalse. -
omit_background: boolHides default white background and allows capturing screenshots with transparency. Defaults tofalse. -
clip: FloatRectAn object which specifies clipping of the resulting image. Should have the following fields:x: floatx-coordinate of top-left corner of clip areay: floaty-coordinate of top-left corner of clip areawidth: floatwidth of clipping areaheight: floatheight of clipping area
-
timeout: floatMaximum time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
-
-
agent: AgentAdditional information to mark baseline across agents that have different:os: stroperating system name, like Windows, Mac, etc.device: strdevice name, PC identifier, mobile identifier etc.viewport: strviewport size.
-
Track element handle
vrt.trackElementHandle(elementHandle, imageName[, options])
-
elementHandle: ElementHandlePlaywright ElementHandle -
imageName: strname for the taken screenshot image -
options: ElementHandleTrackOptionsoptional configuration with:-
diffTollerancePercent: floatspecify acceptable difference from baseline, between0-100. -
ignoreAreas: List[IgnoreArea]x: intX-coordinate relative of left upper cornery: intY-coordinate relative of left upper cornerwidth: intarea width in pxheight: intarea height in px
-
screenshotOptions: ElementHandleScreenshotOptionsconfiguration for Playwrightsscreenshotmethod-
omit_background: boolHides default white background and allows capturing screenshots with transparency. Defaults tofalse. -
timeout: floatMaximum time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
-
-
agent: AgentAdditional information to mark baseline across agents that have different:os: stroperating system name, like Windows, Mac, etc.device: strdevice name, PC identifier, mobile identifier etc.viewport: strviewport 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
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 visual_regression_tracker-4.9.0.tar.gz.
File metadata
- Download URL: visual_regression_tracker-4.9.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7937e9f6229623c14260d5a046a8e0c2d7ac9db0730442ea7ac507d531f97e4
|
|
| MD5 |
f9057780704309033d6a3dfe8dc8c9f9
|
|
| BLAKE2b-256 |
b43ae073f8b335b7c17a5f006fc0b84c20d35f1f4a1304f3edb41e766aaa446c
|
File details
Details for the file visual_regression_tracker-4.9.0-py2.py3-none-any.whl.
File metadata
- Download URL: visual_regression_tracker-4.9.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06d782d54c1b333bc1b204ce3c8a925c2505eda285a35c8856ed1782a8fa5d09
|
|
| MD5 |
1d41da07578ac02a677d60c1bd96c37d
|
|
| BLAKE2b-256 |
b9df5c678290c43c6c1a4e488771fbaf5d70e3f0089f4dfee30358a9c5c7bb13
|