Python SDK for Visual Regression Tracker
pip install visual-regression-tracker
# or, with playwright integration
pip install visual-regression-tracker[playwright]
python -m playwright installfrom visual_regression_tracker import VisualRegressionTracker, Config, TestRunconfig = 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){
"apiUrl":"http://localhost:4200",
"project":"Default project",
"apiKey":"tXZVHX0EA4YQM1MGDD",
"ciBuildId":"commit_sha",
"branchName":"develop",
"enableSoftAssert":false
}vrt = VisualRegressionTracker()VRT_APIURL="http://localhost:4200" \
VRT_PROJECT="Default project" \
VRT_APIKEY="tXZVHX0EA4YQM1MGDD" \
VRT_CIBUILDID="commit_sha" \
VRT_BRANCHNAME="develop" \
VRT_ENABLESOFTASSERT=true \
pythonvrt = VisualRegressionTracker()As context manager:
with vrt:
...
# track test runs
...Without context manager:
vrt.start()
...
# track test runs
...
vrt.stop()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
)
],
))from playwright import sync_playwright
from visual_regression_tracker import Config, TestRun
from visual_regression_tracker.p import PlaywrightVisualRegressionTrackerplaywright = sync_playwright().start()
browserType = playwright.chromium
browser = browserType.launch(headless=False)
page = browser.newPage()
page.goto('https://www.python.org/')vrt = PlaywrightVisualRegressionTracker(browserType, config)As context manager:
with vrt:
...
# track test runs
...Without context manager:
vrt.start()
...
# track test runs
...
vrt.stop()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.
-
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.
-