lecture 20 of 220 completed

Starting and stopping the browser properly

Selenium makes browser lifecycle your job. Getting it wrong leaks processes until the machine stops responding.

What you'll learn

  • Why a failed test can leave a browser running forever
  • Where to put start and quit so they always run
  • How to reuse a browser without leaking state between tests

A build server that slows to a crawl every few days until someone restarts it usually has a suite leaking browser processes. Each run leaves a handful behind. After a week there are hundreds.

Cypress and Playwright manage the browser for you. Selenium does not, and this is where that costs you.

The rule: every browser you start must be stopped, including when the test fails.

The naive version has a bug:

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 →