lecture 4 of 160 completed

Thread safety and parallel execution

The classic senior Selenium interview question, and the bug that makes parallel suites fail in ways nobody can reproduce.

What you'll learn

  • Why sharing one driver across threads interleaves commands
  • How ThreadLocal fixes it, and the line people forget
  • Why thread safety does not fix shared test data

A team enabled parallel execution and their suite started failing randomly. Different tests each run. Sometimes a click landed on the wrong page. Sometimes a test asserted on another test's data. Nothing reproduced in isolation.

They had one driver variable shared across threads. This is the most-asked senior Selenium interview question, and it is worth being able to explain precisely rather than just naming the fix.

Why sharing a driver breaks.

A WebDriver session is one conversation with one browser. Commands carry a session ID and are processed in the order they arrive.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →