Selenium Grid and Parallel Agents
Why This Matters
One local Chrome is enough to learn the agent. It is not enough for a team: users have Firefox and Edge, explorations of a large application take long, and a suite of a few hundred tests needs to run in parallel. Selenium’s answer has been the same for years: Selenium Grid, a hub that hands out browser sessions on nodes.
Selenium AI Agent can drive a Grid. With one setting, the AI gets tools to start a Grid, open sessions in different browsers, explore several parts of an application at once, and run the same steps in several browsers. This lesson shows how, and where the guardrails still apply.
What you will learn
- Connecting the agent to a Grid, and starting one with Docker
- Sessions: create, select, list, destroy
- Parallel exploration and merging the results
- Parallel and cross-browser execution
- What the Grid tools do not change: plans, review, generated tests
Connect a Grid
Set SELENIUM_GRID_URL in the MCP configuration:
{
"mcpServers": {
"selenium-ai-agent": {
"command": "npx",
"args": ["selenium-ai-agent"],
"env": { "SELENIUM_GRID_URL": "http://localhost:4444" }
}
}
}
That loads the grid tool group: 14 tools on top of the 67 you already have. If you don’t use a Grid, leave the group out (SELENIUM_MCP_TOOLSETS, lesson 2): fewer tools means a cheaper and more focused AI.
Start a Grid with Docker
The agent’s repository includes a Docker Compose file for a local Grid: a hub on port 4444, four Chrome nodes and one Firefox node, one session per node, Selenium 4.40. The AI can start it for you:
Start a Selenium Grid with 3 Chrome nodes and 2 Firefox nodes.
grid_start runs Docker Compose with those counts, grid_scale changes them later, grid_stop shuts the Grid down. grid_status shows what is available: whether the Grid is ready, the capacity (for example 0/5 slots used (5 available)), and one line per node with its status, its sessions and its browser and version.
Docker must be installed and running on the machine where the MCP server runs. A company Grid works the same way: point SELENIUM_GRID_URL at it and skip grid_start.
Sessions
On a Grid every browser is a session, and the AI can hold several at once:
| Tool | What it does |
|---|---|
session_create | Open a session in a browser (chrome or firefox on the included Grid; Edge if your Grid has Edge nodes), with tags such as smoke |
session_select | Make a session the active one: all normal tools (navigate_to, click_element, …) now act in it |
session_list | List the open sessions, optionally by tag |
session_destroy / session_destroy_all | Close one session, or all (optionally by tag) |
With session_select, everything you learned so far works per browser:
Open a Firefox session, go to the shop, add the Mechanical Keyboard to the cart and check the cart shows 1 items.
Close sessions when you’re done. A Grid has a fixed number of slots, and an AI that opens sessions and forgets them fills the Grid for everyone. session_destroy_all with a tag cleans up after an experiment.
Parallel exploration
parallel_explore explores several parts of an application at the same time, each in its own session:
{
"baseUrl": "https://practiceautomatedtesting.com",
"targets": [
{ "url": "https://practiceautomatedtesting.com/shopping", "label": "Shop" },
{ "url": "https://practiceautomatedtesting.com/webelements", "label": "Web elements" },
{ "url": "https://practiceautomatedtesting.com/api", "label": "API docs" }
]
}
Up to ten targets, each with its own browser. Every exploration returns an id. Then:
exploration_mergecombines explorations into one site map, without duplicate pages.exploration_diffcompares two explorations, for example last week’s and today’s: pages added, removed or changed. A cheap way to see what a release changed before you plan tests for it.planner_generate_planturns explorations into a test plan.
That last tool writes its plan to test-plans/, and it is a draft, like every plan from planner_save_plan. The generator refuses it until a person has read it (lesson 8). A plan built from a fast parallel crawl needs that review more, not less: it is broader and shallower than a plan the planner made by working through one feature.
Logging in for parallel exploration
parallel_explore can log in for each session: it takes a username, a password and the selectors of the login form. Whatever you put there goes through the chat. The rule from lesson 7 applies: a test account on a test environment only, never a real password.
Parallel and cross-browser execution
parallel_execute runs lists of tool steps in several sessions at once, up to 20 steps per session. The same steps in Chrome and Firefox is a quick cross-browser check:
{
"tasks": [
{ "browser": "chrome", "steps": [
{ "tool": "navigate_to", "arguments": { "url": "https://practiceautomatedtesting.com/shopping" } },
{ "tool": "verify_text_visible", "arguments": { "text": "E-commerce Testing Practice" } }
] },
{ "browser": "firefox", "steps": [
{ "tool": "navigate_to", "arguments": { "url": "https://practiceautomatedtesting.com/shopping" } },
{ "tool": "verify_text_visible", "arguments": { "text": "E-commerce Testing Practice" } }
] }
]
}
That is useful while exploring: does this flow work in Firefox at all? It is not your regression suite. The suite stays what it was: generated test code, run by its own runner, against the Grid.
The generated tests on a Grid
The tests the generator writes start a local browser through the seed (lesson 7). To run them on a Grid, only the seed changes, not the tests:
@pytest.fixture
def shop():
options = webdriver.ChromeOptions()
grid = os.environ.get("SELENIUM_GRID_URL")
driver = webdriver.Remote(command_executor=grid, options=options) if grid else webdriver.Chrome(options=options)
...
Run them in parallel with your runner’s own tool, pytest -n 4 with pytest-xdist for example. That is where the “one fresh browser per test” rule from lesson 7 pays off: independent tests can run in any order, on any node.
All guardrails stay as they are: the plan is reviewed, the rules are checked, the heal policy applies, the gate checks the suite. The Grid only changes where the browsers run.
Exercise
You need Docker for this exercise.
- Set
SELENIUM_GRID_URL=http://localhost:4444and ask the agent to start a Grid with 2 Chrome nodes and 1 Firefox node. Check it withgrid_status. - Ask: “Explore the shop and the web elements page in parallel, then merge the results.” How many pages did each exploration find, and how many after the merge?
- Ask the agent to add the Mechanical Keyboard to the cart in Chrome and in Firefox at the same time and check the cart in both. Then clean up: no sessions left open.
Show suggested answer
grid_startwithchromeNodes: 2, firefoxNodes: 1;grid_statusshows 3 slots.parallel_explorewith two targets returns two exploration ids;exploration_mergewith both ids gives one site map. Pages both explorations reached (the home page, the shared navigation targets) are counted once after the merge.parallel_executewith two tasks, one per browser, each withnavigate_to,click_element(or abatch_execute), and a check of the cart. Thensession_destroy_all;session_listshould be empty andgrid_statusshould show 0 slots used. If you forget, the sessions keep their slots until the Grid’s session timeout ends them.
Exam-style questions
1. What does session_select do?
- A. Opens a new browser on the Grid
- B. Makes a Grid session the active browser for all following tool calls
- C. Selects the fastest node
- D. Selects a test to run
Show answer
2. A plan made by planner_generate_plan from a parallel exploration: may the generator write tests from it straight away?
- A. Yes: it was generated by the agent
- B. No: it is a draft and needs a person’s review, like every plan
- C. Only under
strict - D. Only for Chrome
Show answer
3. How do you run the generated test suite on a Grid?
- A. Regenerate every test for the Grid
- B. Change the seed to start a
webdriver.Remotesession when a Grid URL is set; run the tests in parallel with the runner’s own tool - C. Use
parallel_executefor every test - D. It is not possible