Flaky tests · mid
Flaky tests: CI, headless and environment causes
When a test passes locally and fails in CI, find the difference first. Evidence comes before any fix.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Differences: headless mode, window size (headless mode can use a small default window), slower CPU, less memory, time zone, locale, fonts, network path, browser version, parallel workers.
- Collect evidence first: the failure screenshot, the full exception (it names the element that would get the click), page source, console logs, a video or a trace.
- Example cause: in a small window the responsive layout shows a cookie bar over the Place order button. Fix: set a realistic window size in the driver factory.
- Reproduce by running the same container image locally with the same flags.
- A red nightly run with mixed failures in unrelated areas in a tight time window points to the environment: check deploy history, monitoring, 5xx rate, scheduled jobs, certificate expiry and other teams load tests.
- Add a pre-flight health check (each service /health and a login) that stops the run with "environment not ready". Label failures from 5xx or connection errors as environment.
- Chrome slows and crashes after many tests: look for leaked chrome and chromedriver processes, memory, disk and /dev/shm. Causes: drivers not quit, close() used instead of quit(), and the 64 MB default /dev/shm in Docker.
- Fix with --shm-size=2g or --disable-dev-shm-usage, and quit() in teardown with alwaysRun = true.
The red pen
Common traps: mistake → fix
Mistake: Add waits or raise the timeout
Fix: first open the screenshot; the cause may be layout.
Mistake: File 180 bugs for a red nightly run
Fix: check the environment first.
Mistake: A bigger machine fixes crashes
Fix: find leaked processes and the shm size.
Mistake: --no-sandbox everywhere is a fix
Fix: use it only when you understand why.
Easy to hard
Questions interviewers ask, easy to hard
- A test passes locally and fails in headless CI. What do you do first?
- 180 tests failed at 2 am and passed at 2:30. What happened?
- Chrome crashes after 300 tests in Docker. What do you check?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.