Selenium · Browser automation foundations

When should you run Selenium headless?

EasyheadlesschromeciUpdated Oct 2026
Quiz this track

Short answer

Run headless in CI and containerised environments where no display exists. It is faster and easier to scale, but some visual, download and browser-specific behaviours differ, so keep a headed smoke run where it matters.

Headless browsers render without a visible window. They are the default for CI because they avoid a virtual display server and reduce resource usage. They are still real browsers, so most functional behaviour is identical, but not all of it.

java
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
options.addArguments("--window-size=1440,900");
options.addArguments("--disable-gpu");

WebDriver driver = new ChromeDriver(options);
driver.get("https://example.com");
Assert.assertTrue(driver.getTitle().contains("Example"));
Set an explicit window size; headless defaults can differ from a desktop viewport.
  • Headless avoids the need for Xvfb or a desktop session in CI
  • Set a window size so responsive layouts render predictably
  • Downloads, PDF rendering and some file pickers can behave differently
  • Visual differences may appear in fonts, GPU rendering and animations
  • Older headless mode differed more from headed Chrome; the new mode is closer
  • Debugging is harder without a visible window, so keep screenshots and logs

I run the full functional suite headless in CI and use headed mode locally when investigating a failure. If the product has visual or download-critical flows, I keep a smaller headed job or a visual regression job rather than assuming headless covers everything.

Do not assume headless is automatically faster for every test. Rendering and startup costs vary, and the bigger win is usually removing the display server dependency.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What breaks in headless mode compared with headed mode?
  2. 2Why set a window size in headless runs?
  3. 3How do you debug a failure that only happens in CI?
  4. 4Would you run every test headless?

Say it in the interview

I run headless in CI because there is no display and it scales well in containers. I still set a window size so responsive layouts are deterministic, and I keep screenshots and logs because debugging is harder. Most functional behaviour is the same, but downloads, PDF rendering and visual details can differ. For critical visual flows I keep a headed or visual-regression job rather than assuming headless is equivalent.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Selenium mock interview and get scored feedback on depth, clarity and confidence.