category-iconCASE STUDY

The Silent Performers: How Headless Browsers Automate Testing Like Pros

26 Jul 20250340
Blog Thumbnail

Headless browser automation lets us run browsers invisibly-no windows popping up, just lightning-fast, efficient testing behind the scenes. It’s a game-changer for automated tests, especially in CI/CD pipelines where speed and resource-saving matter most. But here’s the twist: not all browsers play by the same rules. Simply tossing in a --headless flag won’t cut it - each has its own quirks and secrets.

⚠️ Quick heads-up: Safari’s a rebel here. Even in its cutting-edge Safari Technology Preview (STP), true headless mode is off the table. The browser window always shows up, no exceptions - making automation a little more... visible.


🎭 The Illusion of “Headless”

Most think headless means “no browser window.” That’s true, but the story goes deeper:

When launching Chrome or Firefox headless, they’re not ghosts - still full browsers doing all the heavy lifting. Loading pages, running JavaScript, rendering layouts... just offstage.

Think of it like a theater play happening backstage - we don’t see the actors, but the show goes on.

This means:

  • All JavaScript executes fully.
  • DOM renders in memory.
  • Network requests behave as normal.

The only difference is the browser UI isn’t visible.


🧪 Chrome: Quiet but Smart

Chrome gives us powerful headless support, especially with its newer mode. But some websites try to detect when Chrome is running headless and block it.

✅ Basic Setup for Headless Chrome:

options.addArguments("--headless=new"); // New & improved headless mode
options.addArguments("--disable-gpu");  // Helps in Windows environments
driver.manage().window().maximize(); // Maximize after browser launch
options.addArguments("--disable-blink-features=AutomationControlled"); // Hides automation flag


🕵️ Avoid Detection:

Many websites check for navigator.webdriver or missing audio devices to detect bots. Using --disable-blink-features=AutomationControlled helps make automation look more like real user activity.


🐛 Debug in Headless:

Since there’s no visible browser, use screenshots to debug and attach them to your reports for better traceability:

try {
    byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
    saveScreenshotToFile(testName, screenshot); // Custom method to save locally
    Allure.addAttachment("Failure Screenshot - " + testName, new ByteArrayInputStream(screenshot));
} catch (Exception e) {
    e.printStackTrace();
}

This snippet captures a screenshot as bytes, saves it to file, and attaches it to Allure reports - ideal for debugging headless test failures. This snippet captures a screenshot as bytes, saves it to file, and attaches it to Allure reports - ideal for debugging headless test failures.


🦊 Firefox: Clean and Easy

Firefox handles headless mode simply. It doesn’t try to block automation, so we don’t need stealth tweaks.


✅ Headless Firefox Setup:

options.setHeadless(true);
driver.manage().window().maximize(); // Maximize after browser launch
⚠️ Some layouts might look slightly different in headless mode. Always test critical UI parts.


🍏 Safari (and STP): GUI Only

Safari can’t run in true headless mode. Even when automated, it pops up visibly.

To run Safari automation:

  • Use Safari Technology Preview (optional but recommended)
  • Go to Develop → Allow Remote Automation in the menu
  • Enable the driver:
safaridriver --enable

Safari and STP behave the same in automation - STP just gets newer updates first.


⚙️ Using Headless in CI/CD

Headless browsers are perfect for continuous integration tools like Jenkins, GitHub Actions, or GitLab CI. Since they don’t need a display, they run fast and clean.

💡 We run our full UI test suites in CI using headless Chrome and Firefox. It saves time and catches bugs early.


🔍 Quick Spotlight: How Each Browser Plays the Game

  • Chrome leads the pack - powerful, stealthy, and built for headless testing like a pro. Just remember to switch on the new headless mode (--headless=new) for the best results.
  • Firefox keeps it simple and reliable. It’s your go-to when you want straightforward headless runs - just double-check those layouts, because sometimes it likes to do its own thing.
  • Safari marches to a different rhythm - no invisible runs here, as the browser window always appears. Yet, with Safari Technology Preview and Remote Automation activated, your tests remain smooth and reliable.


Headless testing isn’t about hiding - it’s about running smarter. By knowing how each browser behaves behind the scenes, we can build fast, reliable, and stealthy tests that fit right into our pipelines.