How to Perform Visual Regression Testing of UI Components in Storybook
On This Page What is a Component in User Interface?June 23, 2026 · 8 min read · Testing Guide
User Interface of the web coating helps users form the first impression of your web application. It is one of the major success component that can lead to best. The modern web covering architecture postdate a component-based user interface to ensure that each of the components is well-designed and good try. The component-based architecture not only helps develop the application faster but too helps to ship the product in a shorter software development life rhythm. It has many advantages such as faster development, ease of testing, and most significantly multiple developers can work on different parts (components) of the user interface simultaneously. UI Component is a subdivision or elements of the user interface. These are integrated to build the User Interface for any application. User interface is divided into smaller chunks which are called components, and they are developed either parallelly or sequentially, which assist to render a set of characteristic in an reiterative access. Typically, the user interface is built from library. Without UI libraries, one has to build the component from scratch, which is time-consuming. There are several expectation from the components such as,, ease to use, rich aesthetics, etc. Achieving these characteristics from kale want effort and cost. So most organizations choose pre-built UI model such as Angular material, Webix, Material UI, VMware Clarity, etc. for build UI element. Testing the single or subset of UI sections/components is calledUI component examine. The modern such as the Agile poser expects code to be liberate in a shorter span. Hence, QAs can & # 8217; t wait until the complete user interface has been progress; hence, as soon as the component is developed the constituent needs to be tested and delivered. Then the component can be integrated to get the complete exploiter interface. This ideology helps in the faster delivery of high-quality applications. There are several eccentric of examine such as an, API examination, and integrating prove but none of the above tests assures the quality of optical aspects of the application such as fashion, fonts, place, etc. To validate the UI constituent individually, you need UI component examine that helps to test the UI element element by ingredient rather than UI as a whole. It is mainly useful in cases when adding new UI components, and hence they demand to be tested individually. is a testing technique, where two screenshots are compared, and the results are driven found on the comparison of screenshots. There will be two images: baseline and literal. The baseline image is like the expected image, and the actual persona is an image after changing or fixing any UI issues. Storybook provides an environment where one can develop, test, and debug the UI component in isolation. It support all modern UI frameworks such as React, Angular, Vue, etc. Storybook is a Javascript-based open source framework and is most widely used. is habituate to check UI components. is a Visual Testing tool, which allows performing for UI part both manually and automatize. Percy can be integrated with the Storybook to get the most out of UI testing. Percy is the most widely apply and most popular optic essay puppet; some of the best features of Percy are: Percy can be easily integrated with Storybook. This article uses React, Storybook, and Percy tools. Also Read: As a prerequisite, you need to integrate theintegrate Storybook with React Appto start with Visual Testing apply Percy. Using the To-Do app cloned from thisGithubcode base in this guidebook as an example. However, you can use your application to configure Percy Visual Testing for React. Step 1: Install Percy packages Two Percy package you postulate to install are: Use the below bid to install these packet SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. Step 2: Copy the PERCY_TOKEN PERCY_TOKENuniquely identifies your project on Percy & # 8217; s infrastructure. Before executing Percy-Storybook components, you need to copy thePERCY_TOKEN. Steps to get thePERCY_TOKEN (Note:If you don ’ t have a Percy history, you can create one. Alternatively, if you hold a BrowserStack account you can use the same credential to Percy Login.) Step 3: Set up the PERCY_TOKEN environment variable As mentioned above, thePERCY_TOKENunambiguously place your project on Percy & # 8217; s infrastructure, when you execute your tests the Percy CLI seem for thePERCY_TOKENenvironment variable so you require to set thePERCY_TOKENenvironment variable. The Setting up nominal command differs from the command line tool. Use the below command to set up a PERCY_TOKEN environment variable in: Step 4: Execute Percy Storybook Tests Percy catch the screenshot of all your components once you fulfill the tryout. There are multiple shipway to execute your Storybook and Percy Visual Tests. The above dictation starts the Storybook and lade the Storybook components and captures them. The captured screenshot will be uploaded to Percy & # 8217; s infrastructure. Alternatively, you can configure the test dictation shortcut inpackage.jsonand use it by running the following command Once the executing is complete, the bidding line output will demonstrate Percy & # 8217; s build URL. You can navigate to the soma and formalize the test issue. Alternatively, manually log in to Percy, go to Projects, and click on the latest habitus. Note:As mentioned previously in this article, the visual test works by, so the first time when you execute the test the baseline screenshot will be captured which will then be compared against the literal screenshot taken in subsequent test. So you need to run the test at least two times to get valid test results. Percy & # 8217; s establish splasher shows the side-by-side differences if there are any. If there are no differences, Percy bespeak that with the message & # 8220; No Changes & # 8221; Assume that the To-Do app has multiple tasks; tasks can have states like active, completed, etc. you can test these states in thestorybook book with Percy integration. Below is the story fileTodoApp.stories.js, for the to-do task component The above file can be modified to integrate with Percy to take a screenshot of states. The Percy provides an selectionadditionalSnapshots, which facilitate to take a screenshot of various states of the component such as fighting, complete, etc. The above storyfile can be modified to take screenshots of state, as seen below. In the above codification, the subdivisionApp.parametershave some of Percy & # 8217; s parameters likeadditionalSnapshots. The suffix is used to name the image files in Percy & # 8217; s substructure, which helps to secern the image files. Here are some of the good practices to follow during UI Component Testing: Conclusion BrowserStack ’ s is a new generation creature for Visual Testing; it provides a lot of flexibility for the exploiter; since it is a SaaS application, you can see the Visual Results anywhere. This further bring the flexibility to review, accept and disapprove the builds from anywhere. Percy improves the review process and helps in faster development and testing of UI Components. On This Page # Ask-and-Contributeabout this issue 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 Testing of UI Components in Storybook
What is a Component in User Interface?
What is Component Testing of User Interface?
Why is UI Component Testing Important?
Advantages of UI ingredient testing
What is Visual Regression Testing in UI Components?
What is a Storybook?
How to execute Visual Regression Testing for part in Storybook?
npm install -- save-dev @ percy/cli @ percy/storybook
$ Env: PERCY_TOKEN= '' & lt; your-project-token & gt; ''
set PERCY_TOKEN= '' & lt; your-project-token & gt; ''
export PERCY_TOKEN= & lt; your-project-token & gt;
npx percy storybook: start
npm run test
How to test the states of Component in Storybook
//TodoApp.stories.js meaning React, {useState, useRef} from 'react '; import TodoApp from './TodoApp '; exportation default {rubric: 'TodoApp ', element: TodoApp,}; export const App = args = & gt; & lt; TodoApp {... args} / & gt;; // match component name for single tale hoist App.storyName = 'TodoApp '; App.args = {showTodos: 'all ', todos: [{title: 'Foo ', completed: true}, {title: 'Bar ', completed: true}, {title: 'Baz '}, {title: 'Qux '}, {rubric: 'Xyzzy '}]};//TodoApp.stories.js significance React, {useState, useRef} from 'react '; importee TodoApp from './TodoApp '; export nonpayment {title: 'TodoApp ', component: TodoApp,}; export const App = args = & gt; & lt; TodoApp {... args} / & gt;; // match part name for individual story hoisting App.storyName = 'TodoApp '; App.args = {showTodos: 'all ', todos: [{title: 'Foo ', completed: true}, {rubric: 'Bar ', completed: true}, {rubric: 'Baz '}, {rubric: 'Qux '}, {rubric: 'Xyzzy '}]}; App.parameters = {// occupy additional shot of assorted states percy: {additionalSnapshots: [{suffix: ' - Active ', args: {showTodos: 'active '}}, {suffix: ' - Completed ', args: {showTodos: 'completed '}}, {postfix: ' - None ', args: {todos: []}}]}};UI Component Testing Best Practices
Related Guides
Automate This With SUSA
Test Your App Autonomously