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.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →