Running Headless

Headless Chrome and Firefox

CI servers have no screen. Headless browsers render the page in memory. Chrome's modern headless mode (--headless=new) is the same browser as normal Chrome, so results match.

ChromeOptions chrome = new ChromeOptions();
chrome.addArguments("--headless=new", "--window-size=1920,1080",
        "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage");   // last two help in Linux containers

FirefoxOptions firefox = new FirefoxOptions();
firefox.addArguments("-headless", "--width=1920", "--height=1080");

Pitfalls

  • Default headless window is 800×600: responsive menus collapse and elements "disappear". Always set the window size.
  • Screenshots still work in headless mode; keep them on for failures.
  • Debug a CI-only failure by running locally with -Dheadless=true first.

Example

mvn test -Dheadless=true -Dgroups=smoke

Example output

[INFO] Running TestSuite
[INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 39.8 s
[INFO] BUILD SUCCESS