Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteUse JUnit or TestNG to organize Selenium WebDriver tests: create a browser session in a setup hook, perform actions and assertions in a test, and call driver.quit() in teardown. WebDriver controls the browser; the test framework supplies test lifecycle, assertions, and pass/fail reporting. Below are Java examples for both frameworks, along with setup, run, and troubleshooting guidance.
What JUnit and TestNG do in a Selenium test
Selenium WebDriver automates communication with a browser, but it does not itself provide test assertions or decide whether a test passes. JUnit and TestNG provide the test-runner structure around WebDriver. Selenium lists both among the Java runner choices in its guide to organizing and executing Selenium code and describes the responsibilities of its components in the Selenium components overview.
A typical test creates a driver, opens a page, performs an action, checks an observable result, and closes the session. The examples use Selenium’s public sample form at https://www.selenium.dev/selenium/web/web-form.html. They are teaching examples, not claims of an independently executed test.
JUnit Jupiter Selenium example
JUnit Jupiter uses @BeforeEach and @AfterEach for per-test setup and cleanup. This example checks the page title:
Free tools Windows power users keep installed
One-click scans. No signup required.
#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.
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
class SeleniumFormTest {
private WebDriver driver;
@BeforeEach
void setUp() {
driver = new ChromeDriver();
}
@Test
void opensBrowserAndChecksTitle() {
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
assertEquals("Web form", driver.getTitle());
}
@AfterEach
void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
The null check prevents teardown from trying to quit a driver if setup failed before assigning one. Calling quit() closes the browser session rather than leaving it running after a test.
Exercise the form as well as the title
Selenium’s official example also locates the text field and submit button, enters text, submits the form, and checks the resulting page. Add these imports and replace the test method above to cover that interaction:
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.
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
@Test
void submitsTextAndChecksResponse() {
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
driver.findElement(By.name("my-text")).sendKeys("Selenium");
driver.findElement(By.cssSelector("button")).click();
WebElement message = driver.findElement(By.id("message"));
assertEquals("Received!", message.getText());
}
This method belongs in the same class as the setup and teardown hooks. It expects the form’s submission response to display “Received!”.
TestNG Selenium example
TestNG uses @BeforeMethod and @AfterMethod for setup and cleanup around test methods. Its @Test annotation marks the test, and its assertion class is org.testng.Assert.
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 & 11Rank #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.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class SeleniumFormTest {
private WebDriver driver;
@BeforeMethod
public void setUp() {
driver = new ChromeDriver();
}
@Test
public void opensBrowserAndChecksTitle() {
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
Assert.assertEquals(driver.getTitle(), "Web form");
}
@AfterMethod(alwaysRun = true)
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
The alwaysRun = true attribute requests that the after-method configuration run even when preceding methods fail or are skipped. Confirm annotation attributes and runner setup against the TestNG version selected for your project. This is an illustrative adaptation of the Selenium workflow, not a Selenium-published TestNG class.
Set up dependencies and run the test
Use the build system already configured for the project. Selenium’s Java library installation guide shows Maven and Gradle dependency setup. The Selenium Java guide includes selenium-java and a JUnit Jupiter engine in its example configuration; TestNG projects need their chosen TestNG dependency and runner configuration instead. The exact declarations depend on the build file and versions used by the project.
Rank #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
- Choose the framework and add its dependencies. Add Selenium Java and either the JUnit Jupiter engine or TestNG using the official setup guidance and your project’s version conventions.
- Save the test in the project’s test source set. Use the directory and naming conventions recognized by the project’s Maven or Gradle test runner.
- Run the test with the configured build. For a Maven project whose test runner is set up, the Selenium examples repository documentation describes running Java examples with
mvn test. Use the project’s actual runner configuration; a dependency declaration by itself does not establish that the test has run.
Selenium’s downloads page lists Java Selenium 4.49.0 as stable on September 9, 2026. Treat that as a dated release reference, not a requirement to use that version: check the current project documentation and your repository before copying version numbers.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Choose JUnit or TestNG for the suite
Neither framework is universally best for Selenium. Selenium characterizes JUnit as widely used for Java Selenium tests and identifies TestNG’s additional parallel execution and parameterized-test features. TestNG’s documentation also covers data providers and parallel execution configuration. Compare the behaviors your team actually needs:
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →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.
- Lifecycle: JUnit Jupiter’s per-test hooks are
@BeforeEachand@AfterEach; TestNG documents@BeforeMethodand@AfterMethod. - Test data: TestNG documents data providers. Select the framework and configuration that fit how your suite supplies inputs.
- Parallel runs: TestNG documents parallel execution configuration. Decide whether running tests in parallel is part of the build and configure browser sessions accordingly.
- Project conventions: Consider the test stack, IDE, and build tooling already supported by your team before changing frameworks.
JUnit’s JUnit 5 User Guide defines lifecycle annotations such as @BeforeAll and @AfterAll; in the cited versioned guide they normally need to be static unless the per-class test-instance lifecycle is used. Check the guide for the JUnit version in your project before relying on version-specific details.
Common problems and fixes
- The browser does not start: Check that the browser is installed and that the Selenium and browser setup match the project environment. Review the driver startup error and the project’s Selenium setup rather than assuming the test assertion is at fault.
- The test reports that an element cannot be found: Confirm the page loaded and that the locator matches the element on that page. In the form example, the text field uses
name="my-text", the submit button is selected bybutton, and the result is found byid="message". - A test passes locally but leaves browser processes behind: Ensure the teardown hook is present and calls
driver.quit(), including after assertion failures. - The build finds no tests: Check that the class is in the test source set, its naming and annotations match the runner, and the selected JUnit engine or TestNG runner is configured in the build.
- Framework annotation or dependency errors appear: Verify imports and selected dependency versions against the chosen JUnit or TestNG documentation and the project’s Maven or Gradle configuration.
Or skip the browser setup
If your goal is to capture a page image rather than test browser interactions, ScreenshotNeo offers a screenshot API and MCP server. A single GET request can return a PNG, JPEG, WebP, or PDF; see the API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server includes take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo and get 1,000 free screenshots a month with no card.
Frequently Asked Questions
Can I use Selenium without JUnit or TestNG?
WebDriver can automate a browser, but a test suite still needs some way to organize execution and evaluate outcomes; these examples use JUnit Jupiter or TestNG for that role.
Should I create one WebDriver per test?
The examples create a driver in each test’s setup hook, which supports per-test isolation; suites with different performance or parallelization needs should choose and configure their lifecycle deliberately.
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.

