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.

Principle:Webdriverio Webdriverio WebDriver Request Handling

From Leeroopedia
Knowledge Sources
Domains WebDriver, HTTP_Client
Last Updated 2026-02-12 00:00 GMT

Overview

Managing the HTTP request-response cycle for browser automation protocol commands, including retry logic, error classification, and connection pooling.

Description

Browser automation protocols communicate over HTTP, where each command (navigate, click, find element) is expressed as an HTTP request to a specific endpoint on a driver or remote server. WebDriver Request Handling encapsulates the construction, transmission, and interpretation of these HTTP requests. It manages URL routing based on command definitions, serializes command parameters into request bodies, handles authentication headers for remote grid connections, implements configurable retry logic for transient failures (network timeouts, server overload), and transforms HTTP error responses into typed, actionable error objects. Connection pooling ensures efficient reuse of TCP connections across sequential commands, reducing latency in long test sessions.

Usage

This principle applies to any interaction between a test framework and a WebDriver-compatible server. It is the right choice whenever commands must be sent over HTTP to a browser driver, a remote Selenium Grid, or a cloud testing endpoint. It is essential for handling the realities of network communication: intermittent failures, varying response times, and protocol-level error codes that must be translated into meaningful test failures.

Theoretical Basis

The request handling layer implements a command-to-HTTP mapping with resilient execution:

  • Command routing: Each protocol command is defined as a tuple of (HTTP method, URL template, parameter schema). At execution time, the URL template is interpolated with session-specific values (session ID, element ID) and the parameters are serialized into the request body or query string as appropriate.
  • Request pipeline: Each request passes through a pipeline:
    1. Header construction: Content-Type, Authorization (for remote grids), and custom headers are assembled.
    2. Body serialization: Command parameters are JSON-serialized with protocol-specific encoding rules.
    3. Transmission: The request is sent via an HTTP client with configurable timeouts.
    4. Response parsing: The response body is deserialized and inspected for protocol-level errors.
  • Retry strategy: Transient failures trigger an exponential backoff with jitter retry policy:
function executeWithRetry(request, maxRetries):
    for attempt in 0..maxRetries:
        try:
            response = httpClient.send(request)
            if response.status in [200, 201]:
                return parseResult(response)
            else if isRetryable(response.status):
                wait(baseDelay * 2^attempt + randomJitter())
                continue
            else:
                throw classifyError(response)
        catch NetworkError:
            if attempt < maxRetries:
                wait(baseDelay * 2^attempt + randomJitter())
            else:
                throw ConnectionFailedError
  • Error classification: HTTP status codes and WebDriver error codes are mapped to a typed error hierarchy. A 404 on an element endpoint becomes a "stale element reference" error; a 500 with a "session not created" body becomes a session creation failure. This classification enables callers to handle specific failure modes (retry on stale element, abort on session failure).
  • Connection pooling: The HTTP client maintains a pool of persistent connections keyed by host and port. This avoids the overhead of TCP handshake and TLS negotiation for each command, which is significant when hundreds of commands execute per test.

Related Pages

Page Connections

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