How to perform Visual Regression Tests using TestCafe
On This Page What is TestCafe Framework?April 01, 2026 · 8 min read · Testing Guide
Visual Regression Testing (visual testing/visual validation) ensures the UI remains visually logical after codification changes by verifying layouts, styles, and factor across builds. It can be done manually or through automatize screenshot comparison to catch unintended UI differences. With TestCafe, visual regression essay compares new page snapshots against baseline images to flag layout or style shifts across browsers. It integrates directly into TestCafe, making visual checks seamless within CI workflows. Steps to perform visual regression tryout using Test Cafe Option 1: Blink-Diff Plugin Capture baseline screenshot & gt; Capture new screenshot & gt; Compare with Blink-Diff Option 2: Percy Integration Visual Regression Testing Core Workflow This clause explain how to perform visual regression tests use TestCafe. is a modern open-source automation creature establish with NodeJS. Allows the user to encrypt using JavaScript, TypeScript, and CoffeeScript. TestCafe is popular because of its zero-configuration policy, which means, you can just download and start execute your tests. TestCafe supports Visual Regression Testing. There are multiple agency to perform in TestCafe, we are going to discuss two method of Visual Validation Technique in TestCafe. This section continue how to run local visual fixation tests in TestCafe using the open-sourcetestcafe-blink-diff plugin. Step 1:Install theblink-diffnode parcel Install the blink-diff node package using the below dictation Step 2:Write your TestCafe Visual Regression Test Create a new TestCafe test file and gens itvisual-test.js Let & # 8217; s consider a scenario, In the above code We are importingtakeSnapshot, using third-party librarytestcafe-blink-diff We are performing a set of actions for the scenario mentioned utilise the TestCafe syntax. In the end, you can take screenshots use the commandawait takeSnapshot (t); The section below report how to execute the test script for TestCafe Visual Validation. To run visual regression tests in TestCafe, you follow a simple three-step flowing: capture a baseline image, capture the latest UI province, and equate both to detect ocular changes. The elaborate steps are explained below. 1. Capture Base Image To capture the base image, you need to recruit the below command In the above bidding, SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. tests: Folder name where your Testcafe trial exist -s tests/screenshots:Folder name to create a base image, If observe leaflet gens doesn & # 8217; t exist Testcafe creates a new. & # 8211; take-snapshot foot:This is the denotation that deal the captured image as a baseline persona for the future. After execution of the above command, the base ikon will be trance and stored in the screenshots directory 2. Capture Actual Snapshot To capture Actual Snapshot, the command is almost the like as the base image seizure command. The only difference is, at the end instead ofbase specify actuallike below. After executing of the above dictation, the actual ikon will be captured and stored in the screenshots directory 3. Compare Two icon You get the base and actual image, now you need to equate the two picture, for that you need to enroll the below command. In the above command, the threshold is the image departure tolerance, the value can be anywhere between 0 to 3. Test Results Once you recruit the above command, the .html results will be generated, it will testify the result pass/fail along with the image difference In the above method, you will be able to capture full-page snapshots and compare them. The plugin can capture a DOM Element on the webpage, and compare them. To equate the DOM element you need to pass the TestCafe Selector totakeSnapshot () function. For Example, If you want to capture results count (results stats) on the Google Search page, you can write simple codification like the below. The Complete Testcafe code looks like below Execution steps stay the like, once you execute the tryout you will the outcome. Read More: Percy is the most popular Visual Testing Review Platform.Percy is now part of Browserstack. Like Browserstack, Percy also supports all major automation tools. Percy do Visual Testing easier by providing a consecrate comparison page. You can run your visual test in Percy employ TestCafe across many browser and validate them. Integrate Testcafe with Percy for Visual Testing Step 1:Install requires Percy packages To use Percy in your Testcafe fabric, you involve to install two packages, namely@ percy/cli and @ percy/testcafe. Use the below command to install the required package. Step2:Write a Tescafe Percy script to capture a shot Step 3:Add the surroundings Variable Get the Percy project item, by logging into Percy and Navigating to Project scene Set Percy Token Windows Command Prompt Set Percy Token Windows Powershell/Visual Studio Code Terminal Set Percy Token Mac/Linux based Terminal Note:To get the Percy Token you need to create the Percy Project. Step 4:Execute the Percy Visual Tests in Testcafe Using the below command accomplish your Percy Testcafe script The Percy exec command fulfil the TestCafe hand. It performs very similar activeness likenpx testcafe testsbut at the end the snapshot will be sent to Percy ’ s infra. Note: Step 4:View the difference Login to Percy, Click on the several bod you will see the comparison. If there is a difference Percy shows the difference side by side If there is no difference Percy expose the message& # 8220; No Changes & # 8221; Once TestCafe is incorporate, the key advantage of using a cloud-based optical testing platform like include: Pricing Unlike, early picture comparison tools, Percy provides image comparison across browser, and can be easily integrated with Test Automation model like, TestCafe,, and to nominate a few. Moreover, Percy helps in perform. The ocular Comparison proficiency is recommended only for User Interface substantiation, Visual Testing doesn & # 8217; t guarantee any functional flowing or application behavior. In a typical scenario, QA Validation quiz can not be signed off but by Visual Validation. However Visual Testing saves a lot of time and effort which is required for UI proof. # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.How to perform Visual Regression Tests using TestCafe
Overview
npm install testcafe-blink-diff –save-dev
What is TestCafe Framework?
TestCafe Visual Validation (Visual Testing) employ the blink-diff plugin
How to perform Visual Regression Testing utilize TestCafe
npm i testcafe-blink-diff -- save-dev
//visual-test.js import {Selector} from 'testcafe '; import {takeSnapshot} from 'testcafe-blink-diff '; regular ` Visual Testing ` .page ` https: //google.com `; test ('Visual Testing Google Search Results Page ', async t = & gt; {expect t .maximizeWindow () .typeText ('input [name= '' q ''] ', 'Browserstack ') .click ('input [type= '' submit ''] [value= '' Google Search ''] ') .expect (Selector (' # result-stats ') .exists) .ok ({timeout: 5000}); await takeSnapshot (t);});importee {takeSnapshot} from 'testcafe-blink-diff ';Execute Visual Regression Tests in TestCafe
npx testcafe chrome: headless tests -s tests/screenshots -- take-snapshot base
npx testcafe chrome: headless tests -s tests/screenshots -- take-snapshot actual
npx testcafe-blink-diff tests/screenshots -- compare base: real -- exposed -- threshold 0.03
Visual Testing for Specific DOM Element
await takeSnapshot (t, {label: 'google-result-stats ', selector: [Selector (' # result-stats ')]});//visual-test.js import {Selector} from 'testcafe '; import {takeSnapshot} from 'testcafe-blink-diff '; regular ` Ocular Testing ` .page ` https: //google.com `; trial ('Visual Testing Google Search Results Page ', async t = & gt; {await t .maximizeWindow () .typeText ('input [name= '' q ''] ', 'Browserstack ') .click ('input [type= '' submit ''] [value= '' Google Search ''] ') .expect (Selector (' # result-stats ') .exists) .ok ({timeout: 5000}); await takeSnapshot (t, {label: 'google-result-stats ', picker: [Selector (' # result-stats ')]});});Optic Regression employ Testcafe and Percy
npm install -- save-dev @ percy/cli @ percy/testcafe
//visual-test.js import {Selector} from 'testcafe '; import percySnapshot from ' @ percy/testcafe '; fixture ` Optic Testing ` .page ` https: //google.com `; test ('Visual Testing Google Search Results Page ', async t = & gt; {expect t .maximizeWindow () .typeText ('input [name= '' q ''] ', 'Browserstack ') .click ('input [type= '' submit ''] [value= '' Google Search ''] ') .expect (Selector (' # result-stats ') .exists) .ok ({timeout: 5000}); wait percySnapshot (t, 'TestCafe Percy Example ');});set PERCY_TOKEN=your_project_token
$ env: PERCY_TOKEN= '' your_project_token ''
exportation PERCY_TOKEN=your_project_token
npx percy exec -- testcafe chrome: headless trial
Why use BrowserStack Percy?
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously