The Simplest Way to Make Haproxy and Selenium Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Pairing haproxy and selenium routes automated browser traffic across healthy grid nodes in production. This setup balances heavy test loads and stops single browser nodes from crashing. Teams run hundreds of browser tests at the same time to check web apps. A single server cannot handle all those browser sessions at once. Putting a load balancer in front of your test grid solves this problem. It spreads requests across many worker machines and drops dead nodes fast. How traffic and permission

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Pairing haproxy and selenium routes automated browser traffic across healthy grid nodes in production. This setup balances heavy test loads and stops single browser nodes from crashing.

Teams run hundreds of browser tests at the same time to check web apps. A single server cannot handle all those browser sessions at once. Putting a load balancer in front of your test grid solves this problem. It spreads requests across many worker machines and drops dead nodes fast.

How traffic and permissions flow between haproxy and selenium

Selenium uses a central hub or router to manage many browser nodes. Your test runner sends a new session request to the load balancer first. The load balancer checks which grid endpoints are awake and ready for work. It then forwards the test request to a healthy node.

Browser tests are stateful and need sticky routing after the session starts. Every step in a test must hit the exact same browser instance. The load balancer reads the session ID from the test request path or headers. It pins that traffic to the right node until the browser closes.

Permissions flow through two distinct layers during a test run. First, the test runner must prove its identity to the grid endpoint. Teams often use basic auth headers or network rules at the load balancer. Second, the browser itself logs into the staging app under test. That browser uses test user accounts to check app pages and forms.

Common failure modes and how to scope network paths

Timeout mismatches cause the most pain in automated browser grids. A browser node might take thirty seconds to load a heavy page. If the load balancer drops idle links after ten seconds, the test breaks. You must set load balancer timeouts longer than the slowest browser step.

Shared service accounts create another big risk for engineering teams. Many teams hardcode one admin key into every CI pipeline for grid runs. When a test acts up, nobody knows which developer or branch caused the spike. Scoped roles fix this by giving each team or runner a unique identity.

End-to-End Encryption + HAProxy Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged test traffic also blinds security teams during an audit. Staging apps often hold real emails, phone numbers, or card numbers by mistake. If browser nodes sit on a flat network, tests can reach sensitive databases. You should lock down network paths so browser nodes only reach approved test apps. Strict firewall rules stop rogue test scripts from scanning internal servers.

Keeping browser grids fast and clean at scale

Health checks keep your test runs from hanging on broken machines. Browsers leak memory and crash when they run all day. The load balancer can poll the grid status endpoint every few seconds. When a node stops replying, the load balancer pulls it out of rotation.

Good logging at the network edge helps teams fix flaky tests fast. You can log the request time, response code, and node IP for every step. When a test fails, engineers check the logs to spot slow backend responses. Clear network data turns hours of guessing into a quick five-minute fix.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Why do my browser tests fail mid-run behind a load balancer?

Your load balancer is likely sending commands to different nodes without sticky sessions. Or, its idle timeout is shorter than the browser wait time.

Should the load balancer sit in front of the hub or the nodes?

Place it in front of the grid router or hub endpoints for high availability. Let the grid router manage direct traffic to the worker nodes.

How do we stop test scripts from leaking sensitive staging data?

Scope network rules so browser nodes only reach isolated staging apps. Mask fields like emails, phone numbers, and card numbers in test outputs.

The query runs. The emails stay hidden.