Short answer: Cypress is the more turnkey choice when screenshots are part of JavaScript or TypeScript end-to-end tests. Its cy.screenshot() command captures pages, elements, and test-runner views, and cypress run saves a failure screenshot automatically by default. Selenium is a lower-level, highly portable WebDriver capability: the browser returns a Base64-encoded image, and your test code decides how to save, name, crop, compare, and retain it. Neither core API compares images, so visual regression requires a plugin or external service.
What each framework actually captures
| Question | Selenium | Cypress |
|---|---|---|
| Capture API | WebDriver screenshot endpoint, commonly exposed through TakesScreenshot and getScreenshotAs |
cy.screenshot() for the application under test, or cy.get(selector).screenshot() for an element |
| Default artifact location | Your code or test framework chooses it | cypress/screenshots |
| Failure screenshots | You add a listener, hook, or teardown handler | Captured automatically during cypress run when screenshotOnRunFailure is enabled (the default) |
| Built-in image comparison | No | No; Cypress explicitly says it does not perform image comparison itself |
| Browser and language reach | WebDriver drivers and grid infrastructure across languages, desktop browsers, and mobile automation | JavaScript/TypeScript test runner controlling a real browser; Chrome-family browsers and Firefox are documented, with WebKit experimental |
Selenium’s official documentation describes the endpoint as returning a screenshot encoded in Base64 (Selenium screenshot documentation). Cypress documents screenshots for both interactive and headless runs (Cypress screenshot command).
Taking screenshots with Selenium
Java: save a PNG from WebDriver
This complete example opens a page, waits for a visible element, and writes the browser image to a timestamped file. The driver must already be available on your classpath and configured for the browser you run.
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Capture {
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
try {
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
driver.get("https://example.com");
new WebDriverWait(driver, Duration.ofSeconds(15))
.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("h1")));
Path output = Path.of("artifacts", "example.png");
Files.createDirectories(output.getParent());
byte[] png = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
Files.write(output, png);
} finally {
driver.quit();
}
}
}
OutputType.FILE is useful when a framework expects a temporary file; OutputType.BASE64 gives you the encoded string directly. The endpoint and driver determine the supported image format, so treat PNG as the interoperable default unless your driver documents another option.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Full-page and element captures
A normal WebDriver screenshot is generally the current viewport. Full-page behavior differs by browser and driver, so do not assume that setting a tall window produces a reliable full document image. For a specific component, locate the element and use the driver’s element screenshot support where available, or crop the captured image in your own pipeline. This lower-level approach is flexible, but you must define scrolling, lazy loading, clipping, and naming rules yourself.
Adding failure artifacts
Register a framework hook (for example, a JUnit extension or TestNG listener) that checks whether a test failed, calls getScreenshotAs, and writes a path containing the test name, browser, and build identifier. Capture page source and browser logs in the same hook if your diagnosis process needs them. Ensure the hook runs before the driver is quit; otherwise there is no live session from which to capture.
Taking screenshots with Cypress
Capture a page or an element
describe('checkout', () => {
it('captures the confirmation page', () => {
cy.visit('https://example.com/checkout');
cy.get('[data-testid="confirmation"]').should('be.visible');
cy.screenshot('checkout-confirmation', {
capture: 'fullPage',
blackout: ['.customer-email', '.live-chat']
});
});
it('captures one component', () => {
cy.get('.order-summary').screenshot('order-summary');
});
});
Files go to cypress/screenshots by default. Cypress clears that folder before cypress run unless trashAssetsBeforeRuns is changed, so configure CI artifact retention if you need screenshots after a job ends.
Important screenshot options
Cypress supports capture: 'viewport', 'fullPage', and 'runner'. Failure screenshots are coerced to the runner view. Other documented controls include:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
blackoutto hide selectors containing personal or unstable data.overwriteto control whether an existing file is replaced (the default is false).disableTimersAndAnimations, true by default, to reduce moving content while the image is taken.screenshotOnRunFailure, true by default, to disable automatic failure captures when set to false.
Use a stable name and deterministic selectors. If a page contains rotating adverts, timestamps, or animated canvases, blackout or disable those regions before comparing images.
Browser execution
Cypress launches a real browser in an isolated state. Its documented browser support includes Chrome-family browsers (including Edge and Chrome for Testing) and Firefox; WebKit support is experimental (Cypress browser documentation). Pin the browser version in CI when pixel-level consistency matters.
Which is better for visual regression?
Neither Selenium nor Cypress is a complete visual-regression system. A screenshot is only the capture stage. You also need a baseline store, a pixel or perceptual comparison, a difference image, approval workflow, and retention policy. Cypress states this boundary directly: “Cypress does not perform image comparison itself” (Cypress visual-testing documentation).
A reliable comparison workflow
- Fix the viewport, device scale, browser version, operating system, fonts, locale, timezone, and test data.
- Wait for the UI state you intend to approve: network completion alone may not mean fonts or lazy images are ready.
- Mask changing content such as IDs, dates, avatars, ads, and chat controls.
- Capture with the same dimensions and naming convention on every run.
- Compare against an approved baseline using a visual-testing plugin or service.
- Publish the diff and require a human approval for intentional design changes.
Operating systems, browser versions, display scaling, and fonts can change pixels even when the application is correct. Set a small, justified difference threshold rather than hiding broad layout regressions with a permissive threshold.
Recommended Free Tools
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Selenium or Cypress: decision guide
Choose Cypress when
- Your tests are JavaScript or TypeScript and you want screenshot commands beside assertions.
- Element, full-page, and runner captures should work with little custom plumbing.
- Automatic screenshots on headless test failure are valuable in CI.
- You can standardize on Cypress’s supported browser workflow.
Choose Selenium when
- Your organization needs Java, Python, C#, JavaScript, or another WebDriver language.
- You already operate Selenium Grid, cloud browsers, or a custom driver matrix.
- You need low-level control over capture timing, storage, naming, cropping, and artifact handling.
- The same automation layer must cover desktop and mobile WebDriver infrastructure.
Use an external visual service when
Baseline approval, reviewable diffs, parallel browser coverage, or long-term artifact management matters more than owning comparison code. Keep capture and comparison separate so a failed page load is not mistaken for a legitimate visual change.
Reliability, performance, and cost considerations
- Synchronization: wait for a meaningful selector and stable content. A screenshot taken before fonts, images, or client-side data arrive creates false differences.
- Viewport consistency: set width, height, and device scale explicitly in both frameworks.
- Isolation: clear cookies and storage or use a fresh context when state can alter the image.
- Artifacts: store screenshots, diffs, test metadata, and the browser version together; prune large historical sets according to your retention policy.
- Parallel runs: include browser, viewport, and test identifiers in filenames to prevent collisions.
- Cost: Selenium and Cypress are framework components; infrastructure, browsers, CI minutes, storage, and any comparison service are separate expenses. No cited source establishes a performance or adoption advantage for either framework.
Common problems and fixes
The screenshot is blank or incomplete
Usually the page was captured before navigation or rendering finished. Wait for a visible application selector, verify the URL, and ensure lazy-loaded content has entered the viewport. For Selenium, confirm the driver session is still alive when the hook runs.
Only the viewport appears, not the whole page
Selenium’s basic screenshot is a WebDriver capture primitive, not a universal full-page command. Use browser-specific full-page support or compose a scroll-and-stitch routine. In Cypress, set capture: 'fullPage' and check that fixed headers or infinite-scroll content are handled intentionally.
Cypress overwrote or removed an artifact
Give captures unique names, set overwrite: false when appropriate, and remember that cypress run clears the screenshots directory by default. Upload artifacts before the CI workspace is destroyed, or adjust trashAssetsBeforeRuns.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsRank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Every visual test fails after a browser update
Pin browser and operating-system images, install identical fonts, fix device scale, and regenerate baselines only after reviewing the diffs. Do not approve a wholesale baseline change without checking for layout or accessibility regressions.
Failure screenshots contain secrets
Use Cypress blackout selectors or redact images in your Selenium artifact pipeline. Avoid putting tokens in URLs, test data, or filenames, and restrict CI artifact access.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If you only need a clean screenshot from a URL rather than an in-process test artifact, ScreenshotNeo provides a single HTTP request. Its capture can accept cookie and consent banners, remove more than 60 known consent platforms plus newsletter popups and chat widgets, and lets you turn each cleanup step off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers report the page verdict and billing status.
Read the full parameter list in the ScreenshotNeo documentation. The same endpoint can return PNG, JPEG, WebP, or PDF and supports full-page lazy-image loading, CSS-selector element capture, dark mode, device presets or custom viewports, retina scale, custom CSS and JavaScript, clicks, waits, blocked requests, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Existing screenshot API parameter names also work, which can simplify migration.
Free tools Windows power users keep installed
One-click scans. No signup required.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
An MCP server supplies take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients, so an AI agent can request captures without you wiring a browser driver. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots, and every feature is on every plan. Create a free ScreenshotNeo account.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Frequently Asked Questions
Does Cypress compare screenshots by itself?
No. Cypress captures images, but baseline comparison, diff review, and approval require a plugin or external integration.
Can Selenium take screenshots in languages other than Java?
Yes. Selenium exposes the WebDriver capability through language bindings; the Java example uses the documented pattern, while storage and failure hooks remain your responsibility.
Why do identical screenshots differ in CI?
Browser and operating-system versions, fonts, display scaling, locale, animations, and changing application data can all alter pixels. Standardize those inputs and mask dynamic regions.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

