Recommended Free Tools
Use JUnit Jupiter’s @BeforeEach and @AfterEach to start and quit a Selenium WebDriver for every test; put browser actions and assertions in @Test methods. This keeps each test’s browser state isolated and ensures the session is released even when a test fails. The example below follows Selenium’s published Java walkthrough.
How do I use JUnit 5 annotations with Selenium WebDriver?
Use Jupiter annotations consistently: they are in org.junit.jupiter.api, unlike JUnit 4’s org.junit.Test. Add the JUnit Jupiter and Selenium dependencies to your build, ensure the selected Selenium release is compatible with your browser and CI environment, then create a driver before each test and quit it afterward.
Here is a complete test class using Selenium’s sample web form. It checks the page title, enters text, submits the form, and checks the confirmation:
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.Duration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
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;
class WebFormTest {
private WebDriver driver;
@BeforeEach
void setUp() {
driver = new ChromeDriver();
}
@Test
@DisplayName("submits text and shows a confirmation")
void submitsTextAndShowsConfirmation() {
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
assertEquals("Web form", driver.getTitle());
WebElement textBox = driver.findElement(By.name("my-text"));
WebElement submitButton = driver.findElement(By.cssSelector("button"));
textBox.sendKeys("Selenium");
submitButton.click();
assertEquals("Received!", driver.findElement(By.id("message")).getText());
}
@AfterEach
void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
The implicit wait of 500 milliseconds is used in Selenium’s example; it is not a universal wait recommendation. For an application that renders elements asynchronously, synchronize on the relevant condition using the wait strategy your project has chosen rather than adding arbitrary delays. Selenium’s walkthrough includes the Java example and its browser setup context: Organizing and Executing Selenium Code.
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.
What do the main JUnit 5 annotations do in a Selenium test?
| Annotation | Scope and role | Practical use |
|---|---|---|
@Test |
Declares one test method. | Put one behavior and its assertions in the method. |
@BeforeEach |
Runs before each test or parameterized-test invocation. | Create a fresh WebDriver when independent browser state matters. |
@AfterEach |
Runs after each test or parameterized-test invocation. | Call driver.quit() to end the browser session; guard against a null driver if startup may fail. |
@BeforeAll / @AfterAll |
Run once around the test methods in a class. | Static by default. They can be non-static with @TestInstance(TestInstance.Lifecycle.PER_CLASS). |
@DisplayName |
Sets a readable class or method name in test reports. | Describe the behavior, not internal implementation details. |
@ParameterizedTest |
Runs a test for multiple argument sets. | Pair it with a parameter source such as @ValueSource or @CsvSource. |
@RepeatedTest |
Runs a test a specified number of times. | Repetition alone does not vary test data or prove different behaviors. |
@Nested |
Groups related tests in an inner test class. | Use it to organize behaviors by feature or page area. |
@Tag |
Labels tests for filtering. | Use a small, agreed vocabulary such as smoke or slow. |
@Disabled |
Disables a test or class. | Include a reason and remove it when the issue is resolved. |
@ExtendWith |
Registers a Jupiter extension. | Useful for reusable integrations; a hand-written driver lifecycle does not require one. |
JUnit Jupiter’s official guide covers these annotations and their lifecycle rules: JUnit 5 User Guide, version 5.12.0. Jupiter’s @Test is not the JUnit 4 annotation with a different package: do not mix their imports or expect JUnit 4-style annotation attributes in Jupiter.
Should each Selenium test get a fresh browser?
For introductory tests, a fresh driver per test is usually the easier lifecycle to reason about. Jupiter’s default test-instance lifecycle creates a new test-class instance for each test method, but the browser is an external session and still needs explicit teardown.
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.
| Approach | Advantage | Trade-off |
|---|---|---|
Fresh WebDriver per test, with @BeforeEach and @AfterEach |
Independent browser state and straightforward cleanup. | Repeated browser startup adds time. |
Shared WebDriver per class, with @BeforeAll and @AfterAll |
Can reduce browser startup overhead. | Cookies, windows, navigation, and mutable state can leak between tests; define reset rules deliberately. |
Class-level lifecycle methods are static unless the class uses @TestInstance(TestInstance.Lifecycle.PER_CLASS). That mode lets the class-level hooks be non-static, but one test object is shared across methods, so fields can retain state. Choose it only when the shared session has a clear purpose and reset strategy.
How do I test several input values?
Use @ParameterizedTest with a parameter source to exercise the same behavior for multiple inputs. For example, this method accepts two strings as arguments:
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.
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@ParameterizedTest
@ValueSource(strings = { "Selenium", "JUnit Jupiter" })
void acceptsText(String input) {
driver.findElement(By.name("my-text")).sendKeys(input);
// Complete the flow and assert the application-specific result.
}
This is a pattern, not a standalone test: add the page navigation, remaining interaction, and assertion that match your application. The build must include junit-jupiter-params, aligned to the same version as the other Jupiter artifacts.
How should I set up and synchronize the test?
- Choose compatible build dependencies. Select Selenium and JUnit Jupiter releases compatible with the project, and verify their release documentation rather than treating any coordinates as universally current. Include the Jupiter params module if using parameterized tests.
- Use one annotation family. Import Jupiter annotations from
org.junit.jupiter.apiand assertions fromorg.junit.jupiter.api.Assertions. - Confirm browser availability. Selenium’s Java walkthrough uses
ChromeDriver. Driver management behavior and browser compatibility can change; check the selected Selenium release and the browsers available in local or CI environments. - Wait for the condition that matters. When content is asynchronous, wait for the relevant element or state using the project’s chosen synchronization strategy. Do not inflate fixed waits without a reason.
- Always release the session. Use
quit()in teardown.close()closes a window and is not a substitute for ending the full WebDriver session.
Common Selenium and JUnit lifecycle problems
- JUnit does not discover the test: check that the test uses Jupiter’s
@Testimport and that the build is configured for Jupiter, not only JUnit 4. - Parameterized-test annotations are unresolved: add the version-aligned
junit-jupiter-paramsdependency. - A teardown error appears after driver startup fails: guard
driver.quit()with a null check, as in the example. - The test passes alone but fails in a class run: look for shared browser state, especially if using a class-scoped driver. Reset cookies, windows, navigation, and application state, or return to per-test drivers.
- An element is missing intermittently: the page may not have reached the required state when the lookup runs. Wait for the relevant condition instead of relying on arbitrary sleep durations.
- Browser startup fails locally or in CI: check the installed browser and the compatibility and driver-management guidance for your chosen Selenium release.
- Browser processes remain after tests: ensure teardown invokes
quit(), not onlyclose(), and that the teardown method is recognized as Jupiter’s@AfterEach.
Or skip the browser setup
For capturing website screenshots rather than running interactive browser assertions, ScreenshotNeo provides a one-request API. Its API is not a replacement for Selenium tests that click through workflows or assert application behavior.
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
cURL example, adapted to the Selenium sample page; see the ScreenshotNeo documentation for request options:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://www.selenium.dev/selenium/web/web-form.html -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with the response indicating the page verdict and billing status. It also has an MCP server with screenshot, page-info, and PDF-capture tools for AI agents. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
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.
Sources and version scope
The annotation and lifecycle guidance here follows the JUnit Team’s version 5.12.0 User Guide. The Selenium interaction example follows the official Selenium Java walkthrough. Browser and driver compatibility depends on the versions selected for your project and environment.
Frequently Asked Questions
Does JUnit 5 require static @BeforeAll methods?
By default, yes. They may be non-static when the class uses @TestInstance(TestInstance.Lifecycle.PER_CLASS).
Can I use @ParameterizedTest without adding another JUnit module?
No. Include junit-jupiter-params at a version aligned with your other Jupiter artifacts.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteQuick 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.

