Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

ReportNG does not capture Selenium screenshots for you. To attach one to a failed test, capture it in a TestNG listener while the WebDriver is still available, copy Selenium’s temporary image file into a durable location beside the report, and log a link whose relative path resolves from the generated ReportNG page. Then verify the link in the actual report: listener timing, HTML escaping and report relocation can all affect whether it works.

How the screenshot-to-report workflow works

Treat this as two connected jobs: capture and preserve the image, then expose it in the test’s report output. Selenium provides the capture API; TestNG supplies lifecycle callbacks and logging; ReportNG displays TestNG reporter output. The project assembles the link between them. ReportNG documentation describes reporter configuration, not native screenshot capture.

  1. Configure ReportNG and register it with the project’s TestNG run.
  2. In a failure callback, get the WebDriver instance associated with the failing test and capture a screenshot.
  3. Copy the returned temporary file into a stable directory that will travel with the report.
  4. Log a report-relative link and inspect the generated HTML to confirm that it renders and opens the image.

The Selenium Java API describes TakesScreenshot as an interface for a driver or HTML element that can capture a screenshot and store it in different ways. This guide uses the WebDriver form. A separate option is to capture a particular element through an element that supports the interface.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure ReportNG and TestNG

Use the setup instructions for the project’s actual build system and dependency versions. The TestNG-hosted ReportNG documentation covers Maven configuration, service-provider wiring for its HTML and JUnit XML reporters, and Ant listener configuration. It directs command-line, IDE and other build-system users to register custom listeners or reporters through TestNG. Follow the configuration for your environment rather than copying a build snippet that may not match your dependency tree.

#1 Best Overall
Sale
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Auto-Light Balance: RightLight boosts brightness by up to 50%, reducing shadows so you look your best—compared to previous-generation Logitech webcams (1)
  • Privacy with a Slide: The integrated webcam cover makes it easy to get total, reliable privacy when you're not on a video call
  • Built-In Mic: The built-in microphone lets others hear you clearly during video calls
  • Easy Plug-And-Play: The Brio 101 works with most video calling platforms, including Microsoft Teams, Zoom and Google Meet—no hassle; it just works

The TestNG-hosted page labels ReportNG 1.2.2 as its current stable version and says it was tested with TestNG 6.14.3. That is a documented tested combination, not a guarantee of compatibility with every later TestNG or Selenium release. A legacy ReportNG site describes 1.1.4 and TestNG 6.2; prefer the TestNG-hosted documentation and validate the versions actually resolved by your build.

TestNG distinguishes real-time lifecycle callbacks in ITestListener from IReporter, which runs after suites complete. A failure callback is useful for screenshots because it can run before teardown closes the browser—but only if your driver lifecycle leaves that test’s driver available at that point. See TestNG and its logging and results documentation.

Capture and copy the failure screenshot

Call getScreenshotAs(OutputType.FILE) on the failing test’s driver. The OutputType API also documents Base64 and byte-array output forms. The file form is convenient for copying, but Selenium documents it as temporary and deleted when the JVM exits. Do not put its temporary path in a report and expect the image to remain available; copy it to the report’s artifact directory first. Selenium’s documentation example also demonstrates Java screenshot capture and copying.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The following listener shows the integration shape using Java NIO. Replace DriverManager.getDriver() with the project’s own driver lookup, and register the listener using the project’s TestNG configuration. This is an illustrative implementation, not a claim that it has been built against your dependency versions. The output directory and report-relative link must be adjusted to the location of the generated HTML page.

Rank #2
Sale
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • Crisp HD 720p/30 fps video calls with diagonal 55° field of view and auto light correction. Compatible with popular platforms including Skype and Zoom.
  • The built-in noise-reducing mic makes sure your voice comes across clearly up to 1.5 meters away, even if you’re in busy surroundings.
  • C270’s RightLight 2 feature adjusts to lighting conditions, producing brighter, contrasted images to help you look good in all your conference calls.
  • The adjustable universal clip lets you attach the camera securely to your screen or laptop, or fold the clip and set the webcam on a shelf. You’re always ready for your next video call.
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.testng.Reporter;

public class ScreenshotListener implements ITestListener {
    @Override
    public void onTestFailure(ITestResult result) {
        WebDriver driver = DriverManager.getDriver(); // Replace with your driver lookup.
        if (driver == null || !(driver instanceof TakesScreenshot)) {
            Reporter.log("Failure screenshot unavailable: no screenshot-capable driver.");
            return;
        }

        try {
            Path directory = Paths.get("test-output", "screenshots");
            Files.createDirectories(directory);

            String name = safeName(result) + "-" + System.nanoTime() + ".png";
            File temporary = ((TakesScreenshot) driver)
                    .getScreenshotAs(OutputType.FILE);
            Path destination = directory.resolve(name);
            Files.copy(temporary.toPath(), destination,
                    StandardCopyOption.REPLACE_EXISTING);

            // This path assumes the ReportNG HTML page is in test-output/html.
            String reportRelativePath = "../screenshots/" + name;
            Reporter.log("Failure screenshot: <a href="" + reportRelativePath
                    + "">Open image</a>");
        } catch (Exception e) {
            Reporter.log("Failure screenshot could not be saved: "
                    + e.getClass().getSimpleName());
        }
    }

    private static String safeName(ITestResult result) {
        String value = result.getTestClass().getRealClass().getSimpleName()
                + "-" + result.getMethod().getMethodName()
                + "-" + result.getStartMillis();
        return value.replaceAll("[^A-Za-z0-9._-]", "_");
    }
}

In the example, the logged anchor is HTML-escaped as &lt; and &gt; in the Java string, so it will display as literal markup if the report treats it as text. If the generated ReportNG page supports rendered HTML log content, use the markup form appropriate to that version and configuration, then verify the result; do not assume that escaping behavior. The ReportNG page warns that disabling escaping is not recommended because raw log text can become HTML or XML. Keep escaping enabled unless there is a carefully reviewed reason not to, and do not put untrusted test data into raw markup.

The safeName method combines class, method and start time, strips characters unsafe for a simple filename, and adds a nanosecond suffix to reduce collisions. For a parallel or data-driven suite, use a naming scheme that uniquely identifies each invocation; method name alone is not enough. If your project already assigns a unique test or invocation ID, use it instead of relying on a timestamp. Avoid placing credentials, customer data or other sensitive values in a filename or logged link.

Make the link survive report generation and archiving

A link that works from one HTML file may fail from another. The example assumes a report page under test-output/html and images under test-output/screenshots; the relative URL is therefore ../screenshots/.... Your ReportNG output may use a different layout. Open the generated page, inspect the link’s resolved URL, and click it after copying or extracting the complete report directory to a different location.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Create the image directory before copying; the code does this with Files.createDirectories.
  • Archive or publish the screenshots directory along with the report HTML. A link is not an attachment if the image file is omitted.
  • Use a unique filename for every parallel or repeated test invocation to prevent overwriting another failure’s capture.
  • Test the renderer’s escaping behavior with a generated report. A link printed literally is not a clickable link.
  • Handle capture or copy errors without masking the original test failure. The listener above logs a short failure message instead of throwing from the callback.

TestNG’s ReportNG sample output identifies displayed log output as a combination of calls to TestNG Reporter methods. Use Reporter.log(...) to add test-associated output, but confirm the markup and relative URL behavior in the report produced by your own ReportNG version.

Rank #3
Sale
NexiGo N60 1080P Webcam with Microphone, Software Control & Privacy Cover, USB HD Computer Web Camera, Plug and Play, for Zoom/Skype/Teams, Conferencing and Video Calling
  • 【Full HD 1080P Webcam】Powered by a 1080p FHD two-MP CMOS, the NexiGo N60 Webcam produces exceptionally sharp and clear videos at resolutions up to 1920 x 1080 with 30fps. The 3.6mm glass lens provides a crisp image at fixed distances and is optimized between 19.6 inches to 13 feet, making it ideal for almost any indoor use.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 8, 10 & 11 / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.
  • 【Built-in Noise-Cancelling Microphone】The built-in noise-canceling microphone reduces ambient noise to enhance the sound quality of your video. Great for Zoom / Facetime / Video Calling / OBS / Twitch / Facebook / YouTube / Conferencing / Gaming / Streaming / Recording / Online School.
  • 【USB Webcam with Privacy Protection Cover】The privacy cover blocks the lens when the webcam is not in use. It's perfect to help provide security and peace of mind to anyone, from individuals to large companies. 【Note:】Please contact our support for firmware update if you have noticed any audio delays.
  • 【Wide Compatibility】Works with USB 2.0/3.0, no additional drivers required. Ready to use in approximately one minute or less on any compatible device. Compatible with Mac OS X 10.7 and higher / Windows 7, 10 & 11, Pro / Android 4.0 or higher / Linux 2.6.24 / Chrome OS 29.0.1547 / Ubuntu Version 10.04 or above. Not compatible with XBOX/PS4/PS5.

Choose capture timing and output format deliberately

Capture in the failure callback

Use ITestListener.onTestFailure when the browser should still show the state at failure time. This only works if teardown has not already quit the driver and the listener can retrieve the correct instance. If driver cleanup runs earlier, change the lifecycle ordering or capture before cleanup. Do not defer capture to an after-suite reporter and assume a live browser will still exist.

Use Base64 or bytes only when the storage path calls for it

OutputType.FILE is a straightforward choice when the report links to a separate image file. Base64 or byte output can be useful when another component needs to handle the image data directly, but it does not by itself make the image durable or attach it to ReportNG. The report still needs a usable representation or link and a reliable way to serve the image.

Keep report-relative artifacts portable

A relative link avoids binding the report to one machine’s absolute filesystem path, but only if the report and screenshot retain their relative layout when published. If a CI system stores HTML and images as separate artifacts, make sure the link points to the location in the published artifact, not only to a local build directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

The callback reports a null driver or throws after teardown

The driver may be stored in a thread-local or test-context object that the listener cannot access, or teardown may have quit it already. Make the driver lookup use the same test context as the test itself and ensure capture runs before that context is cleared. In parallel runs, never use a shared mutable driver field that can return another test’s browser.

Rank #4
Sale
EMEET C960 1080P Webcam with Microphone, 2 Mics, 90° FOV, Computer Camera
  • 1080P Webcam with Cover for Video Calls - EMEET computer webcam provides design and Optimization for professional video streaming. Realistic 1920 x 1080p video, 5-layer anti-glare lens, providing smooth video. C960 computer camera delivers 1920x1080 video with fixed focus (11.8–118.1 inches), so as to provide a clearer image. C960 USB webcam has a cover and can be removed automatically to meet your needs for privacy. For optimal image performance, use the webcam in a well-lit environment.
  • Built-in 2 Omnidirectional Mics - EMEET webcam with microphone for desktop features 2 built-in omnidirectional microphones, picking up your voice to create clear audio for communication. When installing the webcam, select EMEET C960 as the default microphone input device in your computer and video applications and select C960 as the default device in Zoom/Teams and ensure microphone permissions are enabled for proper use. Please note that C960 does not include built-in speakers.
  • Automatic Light Adjustment - Automatic exposure adjustment is applied in EMEET HD webcam 1080p so that the streaming webcam can deliver stable image performance. EMEET C960 camera for computer also features color adjustment and exposure optimization to help you look your best. For optimal video quality, it is recommended to use the webcam in normal or well-lit environments and select suitable video settings in your application. Proper lighting helps achieve a clearer and more balanced image.
  • Plug-and-Play & Upgraded USB Connectivity - New C960 webcam features both USB Type-A & A-to-C adapter connections for wider compatibility. For stable performance, connect the webcam directly to the computer's main USB port and ensure the device is recognized correctly. If a hub or docking station is used, please ensure it provides sufficient power and stable data transmission, as limited ports may affect performance. 90° wide-angle lens captures more participants without frequent adjustments.
  • High Compatibility & Multi Application - C960 webcam for laptop is compatible with Windows 10/11, macOS 10.14+, and Android TV 7.0+. Not supported: Windows Hello, TVs, tablets, or game consoles. It works with Zoom, Teams, Facetime, Google Meet, YouTube and more. Please select C960 webcam as the default camera and microphone device in your application and ensure camera/microphone permissions are enabled, especially on macOS. (Tips: Incompatible with Windows Hello)

The link appears as literal HTML

ReportNG or TestNG may be escaping log output, so the browser displays the anchor characters instead of rendering a link. Check the generated HTML and the escaping-related Reporter properties documented by ReportNG. Do not turn off escaping casually: ReportNG cautions that unescaped log content becomes HTML/XML. If rendered links are not appropriate for your configuration, log a plain path or use a reviewed custom report/template approach.

The link opens a missing file

Check that the screenshot was copied successfully, then compute the URL from the directory containing the specific ReportNG HTML page—not from the project root. Confirm the screenshot directory was included when the report was moved, archived or uploaded. A relative path can be valid in a local workspace and invalid in a published artifact with a different layout.

One test’s screenshot replaces another’s

Parallel tests or data-provider invocations may share a filename if it is based only on the method name. Include a unique invocation identifier or timestamp and sanitize it for filesystem use. Ensure each callback gets the WebDriver belonging to its own test execution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

No screenshot file is produced

Check that the driver implements TakesScreenshot, that the browser session remains active at callback time, and that the test process can write to the destination. Log capture failures without replacing the original test result, then inspect the listener output and filesystem permissions.

Best Value
Logitech C920x HD Pro PC Webcam Full 1080p/30fps Video - Black
  • Compatible with Nintendo Switch 2’s new GameChat mode
  • HD lighting adjustment and autofocus: The Logitech webcam automatically fine-tunes the lighting, producing bright, razor-sharp images even in low-light settings. This makes it a great webcam for streaming and an ideal web camera for laptop use
  • Advanced capture software: Easily create and share video content with this Logitech camera that is suitable for use as a desktop computer camera or a monitor webcam
  • Stereo audio with dual mics: Capture natural sound during calls and recorded videos with this 1080p webcam, great as a video conference camera or a computer webcam
  • Full HD 1080p video calling and recording at 30 fps. You'll make a strong impression with this PC webcam that features crisp, clearly detailed, and vibrantly colored video

The report stops working after a dependency upgrade

Inspect the resolved Maven or other build dependency tree, confirm ReportNG registration, and create a clean report build. The ReportNG documentation’s stated tested combination is not blanket compatibility assurance for later TestNG versions; verify listener execution, report generation, escaping and artifact paths after version changes.

Or skip the browser setup

For a screenshot of a public page by URL—not the live browser state, cookies or authenticated session of a Selenium test—ScreenshotNeo offers a one-request website screenshot API. It does not replace the listener workflow above or automatically attach an image to ReportNG.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server exposes screenshot tools for AI agents. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. It is made by Yorker Media. Learn about ScreenshotNeo or sign up free for 1,000 screenshots a month, with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate the finished integration

  1. Run a deliberately failing test in a non-production test environment and confirm the listener executes before the driver closes.
  2. Check that a screenshot file appears in the intended artifact directory and can be opened.
  3. Open the generated ReportNG HTML and verify whether the log appears as a clickable link or escaped text.
  4. Move or extract the complete report artifact elsewhere and open the link again.
  5. Repeat with parallel or data-driven tests to confirm each failure gets a distinct image and the correct driver state.

Frequently Asked Questions

Can ReportNG capture a screenshot by itself?

No. The screenshot is captured through Selenium and the project connects it to ReportNG output through TestNG logging or a custom reporting approach.

Should I use TestNG IReporter instead of ITestListener?

Use ITestListener when capture needs to happen during a failure while the browser may still be open. IReporter runs after suites complete and is not a substitute for capturing a live browser before teardown.

Can ScreenshotNeo attach a Selenium failure screenshot to ReportNG?

Not by itself. It captures a website from a URL through its API; it does not access a Selenium session or wire an image into a ReportNG report.

Quick Recap

SaleBestseller No. 1
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black
Logitech Brio 101 Full HD 1080p Webcam for Streaming and Meetings - Black
Compatible with Nintendo Switch 2’s new GameChat mode; Built-In Mic: The built-in microphone lets others hear you clearly during video calls
$35.90
SaleBestseller No. 2
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black
Logitech C270 720p Webcam Plug-and-Play Wide Screen Video Calling - Black
Compatible with Nintendo Switch 2’s new GameChat mode
$16.89
Bestseller No. 5
Logitech C920x HD Pro PC Webcam Full 1080p/30fps Video - Black
Logitech C920x HD Pro PC Webcam Full 1080p/30fps Video - Black
Compatible with Nintendo Switch 2’s new GameChat mode; Fully compatible with Windows 11
$69.99

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.