Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium UrlChecker

From Leeroopedia
Revision as of 11:52, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/SeleniumHQ_Selenium_UrlChecker.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains WebDriver, Infrastructure
Last Updated 2026-02-12 00:00 GMT

Overview

UrlChecker polls one or more URLs until they return HTTP 200 (available) or stop returning HTTP 200 (unavailable), with configurable timeout and exponential backoff.

Description

UrlChecker is a utility class in the org.openqa.selenium.net package that provides two polling methods: waitUntilAvailable and waitUntilUnavailable. It uses a cached thread pool of daemon threads to submit polling tasks that repeatedly open HTTP connections to the target URLs. The polling uses exponential backoff starting from 10ms up to a maximum of 320ms between attempts. Connections use a 500ms connect timeout and 1000ms read timeout. Response streams are fully consumed and closed to allow socket reuse. If the polling exceeds the specified timeout, a UrlChecker.TimeoutException is thrown.

Usage

Use UrlChecker to wait for Selenium Grid hub, node, or standalone server endpoints to become available before running tests, or to confirm that a server has fully shut down before cleanup. It is commonly used in server lifecycle management within Selenium infrastructure.

Code Reference

Source Location

Signature

public class UrlChecker {

    static final int CONNECT_TIMEOUT_MS = 500;

    public void waitUntilAvailable(long timeout, TimeUnit unit, final URL... urls)
        throws TimeoutException

    public void waitUntilUnavailable(long timeout, TimeUnit unit, final URL url)
        throws TimeoutException

    public static class TimeoutException extends Exception {
        public TimeoutException(String s, Throwable throwable)
    }
}

Import

import org.openqa.selenium.net.UrlChecker;

I/O Contract

Method Input Output Description
waitUntilAvailable(long timeout, TimeUnit unit, URL... urls) timeout: max wait time; unit: time unit; urls: one or more URLs to poll void (returns on success) Polls all provided URLs with exponential backoff (10ms to 320ms). Returns as soon as any URL responds with HTTP 200. Throws UrlChecker.TimeoutException if none respond within the timeout.
waitUntilUnavailable(long timeout, TimeUnit unit, URL url) timeout: max wait time; unit: time unit; url: URL to poll void (returns on success) Polls the URL with exponential backoff. Returns when the URL no longer responds with HTTP 200 (non-200 response or connection failure). Throws UrlChecker.TimeoutException if the URL remains available past the timeout.
Constant Value Description
CONNECT_TIMEOUT_MS 500 Connection timeout in milliseconds for each HTTP request
READ_TIMEOUT_MS (private) 1000 Read timeout in milliseconds for each HTTP request
MAX_POLL_INTERVAL_MS (private) 320 Maximum backoff interval between poll attempts
MIN_POLL_INTERVAL_MS (private) 10 Initial backoff interval between poll attempts

Usage Examples

import org.openqa.selenium.net.UrlChecker;
import java.net.URL;
import java.util.concurrent.TimeUnit;

UrlChecker checker = new UrlChecker();

// Wait for a Selenium Grid hub to become available
URL hubUrl = new URL("http://localhost:4444/wd/hub/status");
try {
    checker.waitUntilAvailable(30, TimeUnit.SECONDS, hubUrl);
    System.out.println("Hub is ready");
} catch (UrlChecker.TimeoutException e) {
    System.err.println("Hub did not start in time: " + e.getMessage());
}

// Wait for a server to shut down
try {
    checker.waitUntilUnavailable(10, TimeUnit.SECONDS, hubUrl);
    System.out.println("Hub has stopped");
} catch (UrlChecker.TimeoutException e) {
    System.err.println("Hub did not stop in time");
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment