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

A Selenium 4 end-to-end test in Java opens a real browser, follows a user workflow, waits for the application’s resulting state, asserts that state with a test framework such as JUnit or TestNG, and always closes the browser session. Add Selenium to your build, then let Selenium Manager resolve the browser driver unless your environment needs a pinned, manually managed driver.

What an end-to-end Selenium test needs

Selenium WebDriver controls a browser; it does not supply a Java test runner or assertion framework. Use JUnit or TestNG to discover and run tests, manage setup and teardown, and report assertion failures. Selenium’s documentation names both frameworks but does not rank them or provide a complete comparison. Choose based on your team’s familiarity, fixture and parameterized-test needs, reporting integrations, and parallel-run requirements. Selenium’s test-organization guidance is explicitly incomplete.

The lifecycle of a useful test is straightforward: create a driver, navigate to the application, interact through stable locators, wait for the expected page state, assert the outcome, and quit the driver. The test below illustrates that flow using JUnit Jupiter and a sample form; change the URL, locators, input, and expected result to match your application.

Add Selenium and a test runner

Selenium’s Java binding is distributed as org.seleniumhq.selenium:selenium-java. Add it as a test dependency and deliberately pin versions compatible with the Java runtime and browser environment used by your project. Consult the Selenium installation guide for the current Maven and Gradle examples. Avoid treating the Java minimum or dependency version in Selenium’s older Selenium 4 upgrade guide as current compatibility advice.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.

For example, in a Maven project, put the Selenium dependency in the test scope and add a compatible JUnit Jupiter test dependency. Exact versions change; select them from your project’s current dependency policy rather than copying an old version number from a tutorial. With Gradle, declare the corresponding artifacts in your test dependencies. The Selenium installation page shows both build-tool approaches.

Write a complete Java test

This JUnit Jupiter example assumes your application has a form at https://example.test/form, an email field named email, a submit button matching the CSS selector shown, and a confirmation element with the ID confirmation. Replace these example values with selectors and expected text from your own application. The sample is instructional code, not a claim that it has been executed against a live site.

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

class FormSubmissionTest {
    @Test
    void submittingFormShowsConfirmation() {
        WebDriver driver = new ChromeDriver();
        try {
            driver.get("https://example.test/form");
            driver.findElement(By.name("email")).sendKeys("reader@example.test");
            driver.findElement(By.cssSelector("button[type='submit']")).click();

            WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
            WebElement confirmation = wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.id("confirmation"))
            );
            assertEquals("Submitted", confirmation.getText());
        } finally {
            driver.quit();
        }
    }
}

The assertion comes from JUnit, while WebDriver performs the browser actions. The finally block ensures the browser session is quit even if an interaction, wait, or assertion fails. In a larger suite, move driver creation and cleanup into the test framework’s lifecycle hooks so each test has predictable setup and teardown.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.

Choose locators that survive application changes

Locate controls by attributes or selectors that represent stable application semantics and user-visible behavior. The sample uses a form field name, a button selector, and a confirmation ID; those are examples, not a claim that one locator type is universally best. Prefer selectors your application can keep stable as styling and layout change. If a locator stops matching, verify the page and selector before increasing wait durations.

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

Wait for the state you need

Use an explicit wait for a specific condition that must become true before the next step, such as a confirmation element becoming visible or a control becoming clickable. In the example, WebDriverWait receives a Duration and polls until the visibility condition is met or the timeout expires. The Java API describes WebDriverWait as a specialization of FluentWait<WebDriver>; it ignores NotFoundException by default while evaluating its condition.

Avoid using a fixed sleep as the normal synchronization strategy. It waits even when a page is ready sooner and can still be too short when the page is slower. Selenium’s first-script guide calls implicit wait a placeholder and says it is rarely the best solution. Match an explicit wait to the next action’s required state instead of applying a blanket delay. See the first-script guide for Selenium’s examples.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

Do you still need to download ChromeDriver?

Usually not for a standard Selenium 4 setup. Selenium Manager ships with Selenium releases from 4.6 and is used by the bindings as a fallback when a driver has not otherwise been provided. It can locate, download, and cache drivers. Selenium documents automated browser management starting with version 4.11.0. These version thresholds describe Selenium’s driver-management behavior; check the Selenium Manager documentation for the release and environment you use.

The Selenium project calls Selenium Manager “the official driver manager for Selenium, shipped out of the box with every Selenium release.” You can still supply a driver yourself or use another manager when you need special control over browser and driver versions, such as a pinned test environment. Do not assume a manually installed driver is required simply because older Selenium instructions required one.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Run locally first, then consider Selenium Grid

A local browser is the simplest place to debug a test: run it through your selected test runner, inspect the failing step, and confirm that the browser, application, and test data are available. Put browser setup and cleanup in test lifecycle methods as the suite grows; ensure every started session reaches quit(), including after failures.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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

When you need parallel execution across machines and browser types, evaluate Selenium Grid. Grid is Selenium’s option for distributed browser runs; it adds infrastructure and configuration that depend on your team’s environment, so there is no universal CI setup to copy. Begin with local execution and move to Grid when the need to distribute runs justifies that operational complexity. The Selenium project documentation describes the project and its browser automation capabilities.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

  • Driver or browser cannot be resolved: Check that your Selenium version includes the Selenium Manager behavior you expect, that the browser is installed or available in the environment, and that network or policy restrictions are not preventing driver resolution. If your environment requires strict version control, configure a compatible driver explicitly.
  • An element lookup fails: Confirm the test opened the intended page and that the locator matches the current DOM. If the element appears after an asynchronous update, wait for the appropriate visibility or other state instead of looking it up immediately.
  • The test times out waiting for an element: Verify the expected condition is actually reached in the application, the locator identifies the right element, and the test has reached the correct page or state. Adjust the timeout only after checking those causes.
  • The browser remains open after a failure: Put driver.quit() in a finally block or a test-runner teardown hook, so cleanup runs when assertions or browser commands fail.
  • The suite behaves differently in parallel: Review how driver instances, test data, and shared application state are isolated. Distributed execution requires environment-specific planning; Grid provides the Selenium mechanism for running across machines and browsers, not an automatic guarantee that tests are independent.

Or skip the browser setup

For screenshot capture rather than interactive end-to-end testing, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns an image or PDF; it does not replace Selenium when your test must interact with the application and assert behavior.

cURL example, with the API parameters documented at ScreenshotNeo’s documentation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners before capture and removes 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 cost nothing, and responses identify the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Selenium itself provide Java test assertions?

No. Use an assertion and test framework such as JUnit or TestNG alongside Selenium WebDriver.

Can I use Selenium tests with a browser other than Chrome?

Yes. Selenium WebDriver supports browser automation; select and configure the driver for the browser and environment your project targets.

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.