Package: ez-visual-regression
ez_visual_regressionUsed to take screenshots with selenium (pages or elements) and compare to baselineTable of contentsWhat does ez_visual_regression do?Feature OverviewWhy should I use ez_visual_regression?Quick-startInstallationFrom sourceFrom PyPiExamplesCreate baseline images for testing an elementTest against baseline image for an elementTest a whole page while ignoring h2's and elements with id of myChartAdditional DocumentationWhat does ez_visual_regression do?ez_visual_regressionis a library for helping do visual regression testing. This is a fancy name for taking a screenshot of a known-good version of your app, then every time you make changes you can compare your current app to those screenshots to make sure things don't break.(larger images here)For examplebaselinehere is the "correct" version, we accidentally removed the pricing table incurrent, and we can see the difference indiff(and in higher contrast inthresh). This process is typically quite annoying and needs custom code.ez_visual_regressionmakes this much easier, and integrates natively with selenium, along with nice features (like ignoring elements).Feature overviewOn top of just normal visual regression ez_visual_regression supports:Element ignoring; Usingquery selectors (CSS Selectors)you can select elements who's changes you want to ignore (i.e. hero's with changing images, or the text for commonly changing elements)Full pageorelement based; Allows you to decide if you want to make your tests by full page, or by elementWarning and error thresholds; If you don't want to raise complete red flags you can set error thresholds to say if there "might" be a problem. This logs tostderr, which means you can be more liberal with your measurements without full pipeline failuresPlug-n-play api; The API takes in anynon-headless (standard)webdriver. This means you can doany selenium configurationyou want on the driver and then pass it into the api. It does no more and no less than what each of the functions say.Configuration based testing; You can always use the API if you want a code-based approach, or you can setup a config file and run from the cliWhy should I use ez_visual_regression?There are a ton of great and more robust tools out there for this analysis, or for visual regression testing, but I found each of them had their own problems, here's a list:PackageIssueneedleRequires a Nose test runner, and had out of date dependenciespytest-needleWorks well, but cannot usewebdiver_managerwith itdpxdtDidn't test, but was 7 years old and mostly focused on CI/CD usageVisual Regression TrackerWorks great, but for some of my use cases I need an API not a full applicationhermioneCould not use javascript/nodeJS for my use casespecterCould not use javascript/nodeJS for my use caseCypress-image-screenshotCould not use javascript/nodeJS for my use caseSo I build ez_visual_regression to fill in the gaps I saw in the available solutions. Namely being plug-n-play with any selenium driver to do whatever configurations I need!Quick-startInstallationFrom sourceClone this repo: (put github/source code link here)Runpip install .orsudo pip3 install .in the root directoryFrom PyPiRunpip install ez-visual-regressionExamplesNormally instantiating a browser takes a few steps, for example:fromseleniumimportwebdriver# Instantiates a browserfromselenium.webdriver.chrome.optionsimportOptions# Allows webdriver configfromwebdriver_manager.chromeimportChromeDriverManager# Manages webdriver installfromselenium.webdriver.chrome.serviceimportServiceasChromeService# Helps instantiate browserchrome_options=Options()chrome_options.add_argument("--disable-gpu")chrome_options.add_argument("--no-sandbox")driver=webdriver.Chrome(options=chrome_options,service=ChromeService(ChromeDriverManager().install()))There is an included method to shorten this:fromez_visual_regression.apiimportinstantiate_driverdriver_name="chrome"# Can be "chrome", "edge", or "firefox"driver=instantiate_driver(driver_name)Which is what I will use from here on out, but you can use any method to instantiate a driver and pass it to the functionsCreate baseline images for testing an element# Setup driverfromez_visual_regression.apiimportinstantiate_driverdriver_name="chrome"driver=instantiate_driver(driver_name)# import functions needed for testingfromez_visual_regression.apiimportassert_image_similarity_to_baselineurl="tests/example_sites/no_difference/index.html"# File in this casefolder="tests/example_sites/no_difference"# Where to store output imageslocator="#myChart"# The queryselector to find an element with# Creates baseline if one isn't availableassert_image_similarity_to_baseline(driver,url,locator=locator,folder=folder)Test against baseline image for an element# Setup driverfromez_visual_regression.apiimportinstantiate_driverdriver_name="chrome"driver=instantiate_driver(driver_name)# import functions needed for testingfromez_visual_regression.apiimportassert_image_similarity_to_baselineurl="tests/example_sites/no_difference/index.html"# File in this casefolder="tests/example_sites/no_difference"# Where to store output imageslocator="#myChart"# The queryselector to find an element withtry:assert_image_similarity_to_baseline(driver,url,locator=locator,folder=folder)exceptAssertionError:print("Image too far from baseline!")Test a whole page while ignoring h2's and elements with id of myChart# Setup driverfromez_visual_regression.apiimportinstantiate_driverdriver_name="chrome"driver=instantiate_driver(driver_name)# import functions needed for testingfromez_visual_regression.apiimportassert_image_similarity_to_baselineurl="tests/example_sites/no_difference/index.html"# File in this casefolder="tests/example_sites/no_difference"# Where to store output imagesignored_elements=["h2","#myChart"]# Queryselector for elements to ignoreassert_image_similarity_to_baseline(driver,url,folder=folder,ignored_elements=ignored_elements)Additional DocumentationFor more details check out our:User DocumentationAPI DocumentationChangelogV0.1.0; Oct 1 2023Initial releaseFeaturesAbility to do visual regressionSingle element, full page, and multiple element modesAbilty to hide certain elementsCan set thresholds to errororwarnAbility to invoke test programatically with an APIAbility to invoke test declaritively with a CLIAbility to do simple screenshots in an API and CLI