Selenium¶
Video: Selenium on the same URL (0:45).
Hearth serves the W3C WebDriver protocol the way Selenium Grid 4 does, so a RemoteWebDriver
pointed at the farm works without changes. Sessions run Chrome (Debian's Chromium with a matching
chromedriver) or Firefox (Firefox ESR with geckodriver), each in its own pod.
The URL¶
Both work; use whichever your tooling expects:
The key¶
Selenium clients cannot always set headers, so the gateway accepts the API key as the
password of HTTP basic auth. The user name is ignored; hearth reads well.
Authorization: Bearer <key> and x-hearth-key: <key> work too, if your client can send them.
Node.js (selenium-webdriver)¶
import { Builder } from "selenium-webdriver";
const host = process.env.HEARTH_URL.replace("://", `://hearth:${process.env.HEARTH_KEY}@`);
const driver = await new Builder().usingServer(`${host}/wd/hub`).forBrowser("chrome").build();
try {
await driver.get("https://example.com");
console.log(await driver.getTitle());
} finally {
await driver.quit();
}
Python¶
from selenium import webdriver
from selenium.webdriver.remote.client_config import ClientConfig
hub = "https://hearth.example.com/wd/hub"
config = ClientConfig(remote_server_addr=hub, username="hearth", password=key)
driver = webdriver.Remote(command_executor=hub, options=webdriver.ChromeOptions(), client_config=config)
Java¶
ClientConfig config = ClientConfig.defaultConfig()
.baseUrl(new URL("https://hearth.example.com/wd/hub"))
.authenticateAs(new UsernameAndPassword("hearth", key));
WebDriver driver = RemoteWebDriver.builder()
.oneOf(new ChromeOptions())
.config(config)
.build();
Runnable examples:
selenium-python,
selenium-java,
selenium-node.
Capabilities¶
| Capability | What Hearth does with it |
|---|---|
browserName |
chrome (or chromium) and firefox pick the engine. Anything else is refused with session not created. |
hearth:options |
Farm options, removed before the browser sees them. {"pool": "<name>"} picks a WebDriver pool by name; {"name": "<text>"} names the session (for example the test case), shown in the UI and matched by GET /api/sessions?name=. |
goog:chromeOptions, moz:firefoxOptions |
Hearth always uses the pod's own browser binary, adds --no-sandbox for Chrome (the pod is the sandbox) and sizes the window to the virtual screen. Only args, prefs, excludeSwitches, mobileEmulation, perfLoggingPrefs, windowTypes, log and profile are kept, so extensions and debuggerAddress are dropped. Flags that launch other programs or open remote debugging are removed; see Security. |
browserVersion, platformName |
Removed: each pool runs one browser build on Linux. |
se:* |
Removed. |
To pick a pool by name:
options = webdriver.FirefoxOptions()
options.set_capability("hearth:options", {"pool": "selenium-firefox"})
Without hearth:options.pool, the session goes to a WebDriver pool for that engine (the default
chart has selenium-chrome and selenium-firefox).
Headless and video¶
Sessions run headed on the pod's virtual screen, recorded to video.mp4, and visible in the live
view. If you pass a headless argument (--headless... for Chrome, -headless for Firefox) the
browser runs headless and no video is recorded.
Timeouts¶
- A session with no command for 5 minutes is ended and marked failed with
ended after no command for too long. - If no browser is free,
POST /sessionwaits up to the pool'squeueTimeoutSeconds(120 s by default), then answers HTTP 429 withRetry-After. Raise your client's HTTP read timeout above that if your pools are often full. maxSessionSecondsis not applied to WebDriver sessions yet; the idle timeout is what ends a forgotten session.
Status¶
GET /wd/hub/status (or /status) needs no key and answers like Grid:
ready is false when the gateway cannot reach Redis.
Errors¶
Errors come back in W3C form, so your client raises its normal exceptions:
{"value": {"error": "session not created", "message": "this farm has no \"safari\" browser; use chrome or firefox", "stacktrace": ""}}
A command for a session that ended, or that belongs to another team, gets 404 invalid session id.
Many clients send the key only when they create the session. So for commands on an existing session the key is optional: the session id, long and random, is the credential, as with Selenium Grid. If a key is sent, it must belong to the session's team. Treat session ids like secrets: keep them out of public logs.
Not supported¶
- Grid's own UI and GraphQL endpoints.
- WebDriver BiDi (
webSocketUrl) and Selenium's CDP bridge (se:cdp). For CDP, use/cdp/chromium. - Safari and Edge.