CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-seleniumhq-selenium--selenium-remote-driver

WebDriver remote communication library that provides the core infrastructure for browser automation across different platforms and programming languages.

Pending
Overview
Eval results
Files

command-execution.mddocs/

Command Execution

HTTP-based command execution framework that handles the communication protocol between WebDriver clients and remote browser instances. This system provides the foundation for all WebDriver operations by translating high-level commands into HTTP requests and processing responses.

Capabilities

CommandExecutor Interface

Core interface for executing WebDriver commands, providing the abstraction layer between WebDriver operations and transport mechanisms.

/**
 * Interface for executing WebDriver commands
 */
public interface CommandExecutor {
    /**
     * Execute a WebDriver command and return the response
     * @param command The command to execute
     * @return Response from the command execution
     * @throws IOException if communication fails
     */
    Response execute(Command command) throws IOException;
}

HttpCommandExecutor

HTTP-based implementation of CommandExecutor that communicates with remote WebDriver endpoints using HTTP protocol.

/**
 * HTTP-based command executor for communicating with remote WebDriver endpoints
 */
public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
    
    // Constructors
    public HttpCommandExecutor(URL addressOfRemoteServer);
    public HttpCommandExecutor(ClientConfig config);
    public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, 
                              URL addressOfRemoteServer);
    public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, 
                              URL addressOfRemoteServer, ClientConfig config);
    public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, 
                              URL addressOfRemoteServer, HttpClient.Factory httpClientFactory);
    public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, 
                              ClientConfig config, HttpClient.Factory httpClientFactory);
    
    // Command execution
    public Response execute(Command command) throws IOException;
    
    // Configuration access
    public Map<String, CommandInfo> getAdditionalCommands();
    public URL getAddressOfRemoteServer();
    public void setLocalLogs(LocalLogs logs);
    
    // Factory methods
    public static HttpClient.Factory getDefaultClientFactory();
}

Usage Examples:

import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.Response;
import java.net.URL;

// Basic HTTP command executor
HttpCommandExecutor executor = new HttpCommandExecutor(
    new URL("http://localhost:4444/wd/hub"));

// Execute a command
Command command = new Command(null, DriverCommand.GET_CURRENT_URL);
Response response = executor.execute(command);

// With additional commands and configuration
Map<String, CommandInfo> customCommands = new HashMap<>();
customCommands.put("customCommand", 
    new CommandInfo("GET", "/custom/endpoint"));

HttpCommandExecutor customExecutor = new HttpCommandExecutor(
    customCommands, 
    new URL("http://localhost:4444/wd/hub"));

TracedCommandExecutor

Command executor wrapper that adds distributed tracing support for observability in complex testing environments.

/**
 * Command executor that adds distributed tracing to command execution
 */
public class TracedCommandExecutor implements CommandExecutor {
    
    public TracedCommandExecutor(CommandExecutor executor, Tracer tracer);
    public Response execute(Command command);
}

Usage Examples:

import org.openqa.selenium.remote.TracedCommandExecutor;
import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;

// Wrap existing executor with tracing
CommandExecutor baseExecutor = new HttpCommandExecutor(gridUrl);
Tracer tracer = OpenTelemetryTracer.getInstance();
CommandExecutor tracedExecutor = new TracedCommandExecutor(baseExecutor, tracer);

// Use in RemoteWebDriver
RemoteWebDriver driver = new RemoteWebDriver(tracedExecutor, capabilities);

Command

Represents a WebDriver command with session context and parameters.

/**
 * Represents a WebDriver command to be executed
 */
public class Command {
    
    // Constructors
    public Command(SessionId sessionId, String name);
    public Command(SessionId sessionId, String name, Map<String, ?> parameters);
    public Command(SessionId sessionId, CommandPayload payload);
    
    // Accessors
    public SessionId getSessionId();
    public String getName();
    public Map<String, ?> getParameters();
}

Usage Examples:

import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.DriverCommand;
import java.util.Map;
import java.util.HashMap;

// Simple command
Command getTitle = new Command(sessionId, DriverCommand.GET_TITLE);

// Command with parameters
Map<String, Object> params = new HashMap<>();
params.put("url", "https://example.com");
Command navigate = new Command(sessionId, DriverCommand.GET, params);

// Using DriverCommand factory methods
Command clickElement = DriverCommand.CLICK_ELEMENT("element-id-123");

CommandPayload

Encapsulates command name and parameters without session context.

/**
 * Encapsulates command name and parameters
 */
public class CommandPayload {
    
    public CommandPayload(String name, Map<String, ?> parameters);
    
    public String getName();
    public Map<String, ?> getParameters();
}

Response

Represents the response from a command execution, containing status, value, and session information.

/**
 * Represents response from command execution
 */
public class Response {
    
    // Constructors
    public Response();
    public Response(SessionId sessionId);
    
    // Status handling (deprecated)
    @Deprecated
    public Integer getStatus();
    @Deprecated
    public void setStatus(Integer status);
    
    // State handling (W3C standard)
    public String getState();
    public void setState(String state);
    
    // Value handling
    public Object getValue();
    public void setValue(Object value);
    
    // Session handling
    public String getSessionId();
    public void setSessionId(String sessionId);
}

Usage Examples:

import org.openqa.selenium.remote.Response;

// Process command response
Response response = executor.execute(command);
if (response.getState() != null) {
    // Handle error state
    throw new WebDriverException("Command failed: " + response.getState());
}

Object result = response.getValue();
String sessionId = response.getSessionId();

DriverCommand Constants

Constants and factory methods for all WebDriver commands defined in the W3C specification.

/**
 * Constants and factory methods for WebDriver commands
 */
public interface DriverCommand {
    
    // Session commands
    String NEW_SESSION = "newSession";
    String QUIT = "quit";
    
    // Navigation commands
    String GET = "get";
    String GO_BACK = "goBack";
    String GO_FORWARD = "goForward";
    String REFRESH = "refresh";
    String GET_CURRENT_URL = "getCurrentUrl";
    String GET_TITLE = "getTitle";
    String GET_PAGE_SOURCE = "getPageSource";
    
    // Element commands
    String FIND_ELEMENT = "findElement";
    String FIND_ELEMENTS = "findElements";
    String CLICK_ELEMENT = "clickElement";
    String SEND_KEYS_TO_ELEMENT = "sendKeysToElement";
    String GET_ELEMENT_TEXT = "getElementText";
    String GET_ELEMENT_TAG_NAME = "getElementTagName";
    String GET_ELEMENT_ATTRIBUTE = "getElementAttribute";
    String GET_ELEMENT_PROPERTY = "getElementProperty";
    String IS_ELEMENT_SELECTED = "isElementSelected";
    String IS_ELEMENT_ENABLED = "isElementEnabled";
    String IS_ELEMENT_DISPLAYED = "isElementDisplayed";
    String GET_ELEMENT_LOCATION = "getElementLocation";
    String GET_ELEMENT_SIZE = "getElementSize";
    String GET_ELEMENT_RECT = "getElementRect";
    String CLEAR_ELEMENT = "clearElement";
    String SUBMIT_ELEMENT = "submitElement";
    
    // JavaScript commands
    String EXECUTE_SCRIPT = "executeScript";
    String EXECUTE_ASYNC_SCRIPT = "executeAsyncScript";
    
    // Screenshot commands
    String SCREENSHOT = "screenshot";
    String ELEMENT_SCREENSHOT = "elementScreenshot";
    
    // Window commands
    String GET_WINDOW_HANDLES = "getWindowHandles";
    String GET_WINDOW_HANDLE = "getWindowHandle";
    String SWITCH_TO_WINDOW = "switchToWindow";
    String CLOSE = "close";
    String GET_WINDOW_SIZE = "getWindowSize";
    String SET_WINDOW_SIZE = "setWindowSize";
    String GET_WINDOW_POSITION = "getWindowPosition";
    String SET_WINDOW_POSITION = "setWindowPosition";
    String MAXIMIZE_WINDOW = "maximizeWindow";
    String MINIMIZE_WINDOW = "minimizeWindow";
    String FULLSCREEN_WINDOW = "fullscreenWindow";
    
    // Frame commands
    String SWITCH_TO_FRAME = "switchToFrame";
    String SWITCH_TO_PARENT_FRAME = "switchToParentFrame";
    
    // Alert commands
    String GET_ALERT_TEXT = "getAlertText";
    String ACCEPT_ALERT = "acceptAlert";
    String DISMISS_ALERT = "dismissAlert";
    String SET_ALERT_VALUE = "setAlertValue";
    
    // Cookie commands
    String ADD_COOKIE = "addCookie";
    String GET_ALL_COOKIES = "getCookies";
    String GET_COOKIE = "getCookie";
    String DELETE_COOKIE = "deleteCookie";
    String DELETE_ALL_COOKIES = "deleteAllCookies";
    
    // Timeout commands
    String SET_TIMEOUT = "setTimeout";
    
    // Actions commands
    String ACTIONS = "actions";
    String RELEASE_ACTIONS = "releaseActions";
    
    // Factory methods for creating command payloads
    static CommandPayload NEW_SESSION(Capabilities capabilities);
    static CommandPayload GET(String url);
    static CommandPayload FIND_ELEMENT(String strategy, Object value);
    static CommandPayload CLICK_ELEMENT(String id);
    static CommandPayload SEND_KEYS_TO_ELEMENT(String id, CharSequence... keys);
    // ... many more factory methods
}

Usage Examples:

import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.CommandPayload;
import org.openqa.selenium.By;

// Using command constants
String commandName = DriverCommand.GET_TITLE;

// Using factory methods
CommandPayload navigate = DriverCommand.GET("https://example.com");
CommandPayload findElement = DriverCommand.FIND_ELEMENT("id", "submit-button");
CommandPayload clickElement = DriverCommand.CLICK_ELEMENT("element-123");

// Create complete command
Command command = new Command(sessionId, navigate);

CommandInfo

Represents HTTP method and URL template information for WebDriver commands.

/**
 * Information about how to execute a specific command via HTTP
 */
public class CommandInfo {
    
    public CommandInfo(String method, String url);
    
    public String getMethod();
    public String getUrl();
}

Error Handling

Comprehensive error handling for command execution failures.

/**
 * Handles error responses from remote WebDriver endpoints
 */
public class ErrorHandler {
    
    public ErrorHandler();
    public ErrorHandler(boolean includeServerErrors);
    
    public void throwIfResponseFailed(Response response, long additionalTime);
    public boolean isIncludeServerErrors();
}

Usage Examples:

import org.openqa.selenium.remote.ErrorHandler;

// Process response with error handling
ErrorHandler errorHandler = new ErrorHandler(true);
Response response = executor.execute(command);
errorHandler.throwIfResponseFailed(response, System.currentTimeMillis());

Install with Tessl CLI

npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-remote-driver

docs

capabilities-management.md

command-execution.md

distributed-tracing.md

driver-services.md

http-communication.md

index.md

webdriver-operations.md

tile.json