How to capture Lazy Loading Images for Visual Regression Testing in Puppeteer
On This Page What is Ocular TestingWhat are Lazy Loaded ImagesMay 30, 2026 · 9 min read · Performance Testing
Modern web applications progressively rely on lazy-loading techniques to improve execution and charge hurrying. However, lazy-loaded images can easily break visual fixation testing if they aren ’ t fully rendered before a screenshot is conduct. That ’ s where Puppeteer comes to play. How Work-shy Loading Works in Puppeteer? Puppeteer behaves like a real user, so images won ’ t payload until they ’ re scrolled into view, whether using aboriginalloading= & # 8221; lazy & # 8221;or JavaScript-based lazy loading. In order to enamor complete, reliable visuals, it is important to use the right techniques to trigger and load every lazy-loaded factor before testing. 1. Native Lazy Loading (loading= & # 8221; lazy & # 8221;) If the site uses nativeloading= & # 8221; lazy & # 8221;which is supported by Chromium, Puppeteer load ikon as they enter the viewport, and simple scrolling is adequate to trigger them. 2. JavaScript-Based Lazy Loading (Intersection Observer, Custom Scripts) For, Puppeteer must assume user interaction, especially scrolling, to implement the lazy-load logic. 3. Wait for Images to Finish Loading after scroll: 4. Increase Viewport Size (Optional):A larger viewport can display more images at once, reduce how much scrolling Puppeteer postulate to perform. 5. Disable JavaScript (Rare Use Case):Only when JS controls otiose load and you want the initial HTML without loading the images. This is not recommend for ocular testing. This clause explore how to capture lazy-loaded ikon for visual fixation testing using Puppeteer effectively. Testing the Visual aspect of the web page is phone. Optic Testing is also called Optical Validation or. Visual testing can be do by compare two snapshots (base and actual). Visual Testing can be automated and done manually. compares baseline and existent screenshots to detect optic discrepancies. It can be done manually or through automated instrument to highlight differences. It ensures UI consistence, enhances user experience, and prevents visual bugs across browsers and devices. Learn More: Lazy-loaded picturerefer to persona on a web page that aren ’ t instantly loaded when the page is first rendered. These images are loaded just when the user reaches the piece of the page where they are actually located (the user ’ s viewport). is beneficial for media-heavy websites, ensuring a smoother user experience while optimizing bandwidth usage. However, proper effectuation is indispensable to foreclose issues like delayed rendering or miss images in and search engine indexing. Also Read: Lazy loading is widely adopted because it offers several performance benefits: Also Read: Despite its benefits, lazy loading introduces some challenges in testing such as: Read More: It is indispensable to beguile Lazy-loaded images during to facilitate the visual and functional integrity of an application Learn More: was initially designed for. But you can perform Visual Validation Testing using third-party software. Must Read: One of the challenges in visual validation is try lazy burden websites. As the web page plus will be lade dynamically as the user scroll downwardly, if you enamor the shot after piloting, but part of the web page gets charm. To overcome the lazy loading trouble in Visual Testing, the simplest solution is to scroll to the bum of the webpage before taking the screenshot. Prerequisites: Step 1: Install jest-image-snapshot SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. Consider the webpage https: //sdk-test.percy.dev/lazy-loading when you navigate to this webpage, only a few images loads, as you scroll down, the images keep loading until it reaches picture figure 40. To direct the above issue, you need to follow the below stairs Note: Full webpage screenshot direct the consummate webpage screenshot, not just the viewable area of the website. Step 2: Install thescroll-to-bottomjs Puppeteer doesn & # 8217; t provide any unmediated command to scroll to the tooshie. The scroll-to-bottom action can be achieved by the third-party pluginscroll-to-bottomjs. Command: Step 3: Write Optic Regression Test using Puppeteer for Lazy load webpage Let & # 8217; s see what the above code snippet perform, Step 4: Execute your Visual Comparison Tests using Puppeteer Execute your Jest Puppeteer Visual Regression Test using the bid Alternatively, if you receive configured the tests require in package.json you can simply fulfill npm run tryout The first time you fulfill the exam, Puppeteer captures the base screenshot, the subsequent run compares the actual screenshot with the bag screenshot. The pass/fail consequence will be shown on the command line Example Output shows the failed scenario: __diff_output__ folder shows the snapshot difference Once has loaded all lazy-loaded images and the page is full interpret, the next measure is ensuring that these visuals remain consistent across code changes. This is where Percy by BrowserStack append important value. is an AI-powered optic testing platform that automates screenshot capture, comparison, and reappraisal. It handles the integral visual regression workflow, get it easy to get layout shifts, styling issues, or changes caused by lazy-loaded content. Pricing Options for Percy Step 1: Install @ percy/puppeteer and @ percy/cli using npm: Step 2: Write Puppeteer Tests using Percy In the Puppeteer test, the percySnapshot needs to be import, in order to take a screenshots Once you import the percySnapshot, you can perform a set of actions and then lead a screenshot at the required stride. Note: Ensure you hold installed scroll-to-bottomjs npm package, as explained in the first part of this tutorial. Step 3: Set PERCY_TOKEN Navigate to Percy Project Settings (If Project is not created already create one) and copy the PERCY_TOKEN. Set the environs variable as per your tool. Step 4: Execute Percy Test Execute Percy Visual Test for Puppeteer and Jest using the below bidding. Once the Percy Test is completed, you will see the results in the command line with the Percy make number. Navigate to the URL to get the details. Once you Navigate to the Build URL, the persona diff overlayer will be laden side by side if there is any difference. If there is no difference Percy just shows & # 8220; No Changes. & # 8221; Visual Regression is crucial for the visual correctness of the coating which might get unnoticed while. Considering the UI aspect of the application, automated Optic Validation Testing saves time and attempt, besides it doesn ’ t postulate any expertise in befool. The modern frameworks that implement indolent load can have infinite scrolling, in such scenarios, it is very hard to perform manual optical testing. You can use tools like BrowserStack Percy to heighten this operation and automate visual compare by integrating with Puppeteer. On This Page # Ask-and-Contributeabout this subject 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 capture Lazy Loading Images for Visual Regression Testing in Puppeteer
Overview
await page.evaluate (() = & gt; {window.scrollBy (0, window.innerHeight);});What is Visual Testing
What are Lazy Loaded Images
Advantages of Lazy Loading Images
Disadvantages of Lazy Loading Images
Why is it Important to Capture lazy-loaded Images for Optic Regression Testing
Visual Regression Testing in Puppeteer
How to capture Lazy Loading Images for Visual Regression Testing in Puppeteer
npm i -- save-dev jest-image-snapshot
npm i scroll-to-bottomjs
//visual-lazyloading.test.js const {toMatchImageSnapshot} = require ('jest-image-snapshot '); let scrollToBottom = require (`` scroll-to-bottomjs ''); expect.extend ({toMatchImageSnapshot}); describe ('Visual Testing - Lazy Loading ', () = & gt; {jest.setTimeout (50000); beforeAll (async () = & gt; {await page.goto ('https: //sdk-test.percy.dev/lazy-loading ')}) it ('Visual Regression Test - Lazy Loading ', async () = & gt; {await page.evaluate (scrollToBottom); await page.waitForTimeout (5000); const image = await page.screenshot ({fullPage: true}); expect (image) .toMatchImageSnapshot ({failureThreshold: ' 0.10 ', failureThresholdType: 'percent'});})})npx jest -c ./jest.config.js
Scaling Visual Regression Testing with Percy
Why Use Percy with Lazy-Loaded Pages?
Visual Testing using Percy Puppeteer for Lazy Loading Website
npm install -- save-dev @ percy/cli @ percy/puppeteer
const percySnapshot = require (' @ percy/puppeteer ')let scrollToBottom = require (`` scroll-to-bottomjs '');
//visual-percy-lazyloading.test.js const percySnapshot = require (' @ percy/puppeteer ') let scrollToBottom = require (`` scroll-to-bottomjs ''); describe ('Visual Testing Percy-Lazy Loading ', () = & gt; {jest.setTimeout (50000); beforeAll (async () = & gt; {await page.goto ('https: //sdk-test.percy.dev/lazy-loading ')}) it ('Visual Regression Test Percy - Lazy Loading ', async () = & gt; {look page.evaluate (scrollToBottom); await page.waitForTimeout (5000); await percySnapshot (page, `` percy-lazyload-visual-test-puppeteer-jest '')})})set PERCY_TOKEN= & lt; your item here & gt;
export PERCY_TOKEN= & lt; your token here & gt;
$ env: PERCY_TOKEN= '' & lt; your token hither & gt; ''
npx percy exec -- jest -c ./jest.config.js
Useful Resources for Lazy Loading
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously