Package: visual-regression-tracker
Python SDK forVisual Regression TrackerInstallpipinstallvisual-regression-tracker# or, with playwright integrationpipinstallvisual-regression-tracker[playwright]python-mplaywrightinstallUsageImportfromvisual_regression_trackerimportVisualRegressionTracker,Config,TestRunConfigure connectionAs pythonconfig=Config(# apiUrl - URL where backend is runningapiUrl='http://localhost:4200',# project - Project name or IDproject='Default project',# apiKey - User apiKeyapiKey='tXZVHX0EA4YQM1MGDD',# ciBuildId - Current git commit SHAciBuildId='commit_sha',# branch - Current git branchbranchName='develop',# enableSoftAssert - Log errors instead of exceptionsenableSoftAssert=False,)vrt=VisualRegressionTracker(config)Or, as JSON config filevrt.json{"apiUrl":"http://localhost:4200","project":"Default project","apiKey":"tXZVHX0EA4YQM1MGDD","ciBuildId":"commit_sha","branchName":"develop","enableSoftAssert":false}vrt=VisualRegressionTracker()Or, as environment variablesVRT_APIURL="http://localhost:4200"\VRT_PROJECT="Default project"\VRT_APIKEY="tXZVHX0EA4YQM1MGDD"\VRT_CIBUILDID="commit_sha"\VRT_BRANCHNAME="develop"\VRT_ENABLESOFTASSERT=true\pythonvrt=VisualRegressionTracker()Setup / TeardownAs context manager:withvrt:...# track test runs...Without context manager:vrt.start()...# track test runs...vrt.stop()Assertvrt.track(TestRun(# Name to be displayed# Requiredname='Image name',# Base64 encoded string# RequiredimageBase64=image,# Allowed mismatch tollerance in %# Optional# Default: 0%diffTollerancePercent=1,# Optionalos='Mac',# Optionalbrowser='Chrome',# Optionalviewport='800x600',# Optionaldevice='PC',# Array of areas to be ignoredignoreAreas=[IgnoreArea(# X-coordinate relative of left upper corner# Requiredx=10,# Y-coordinate relative of left upper corner# Requiredy=20,# Area width in px# Requiredwidth=300,# Height width in px# Requiredheight=400)],))Integration with Microsoft PlaywrightImportsfromplaywrightimportsync_playwrightfromvisual_regression_trackerimportConfig,TestRunfromvisual_regression_tracker.pimportPlaywrightVisualRegressionTrackerStart playwright and navigate to pageplaywright=sync_playwright().start()browserType=playwright.chromiumbrowser=browserType.launch(headless=False)page=browser.newPage()page.goto('https://www.python.org/')Configure connection to VRT servervrt=PlaywrightVisualRegressionTracker(browserType,config)Setup / Tear downAs context manager:withvrt:...# track test runs...Without context manager:vrt.start()...# track test runs...vrt.stop()Track pagevrt.trackPage(page,imageName[,options])page: PagePlaywright pageimageName: strname for the taken screenshot imageoptions: 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 pxscreenshotOptions: PageScreenshotOptionsconfiguration for Playwrightsscreenshotmethodfull_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 areatimeout: 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 handlevrt.trackElementHandle(elementHandle,imageName[,options])elementHandle: ElementHandlePlaywright ElementHandleimageName: strname for the taken screenshot imageoptions: 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 pxscreenshotOptions: ElementHandleScreenshotOptionsconfiguration for Playwrightsscreenshotmethodomit_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.