Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

How to Run WebdriverIO Tests in Headless Mode

Add the browser-specific headless flag to WebdriverIO capabilities, run the configured testrunner, and use Xvfb on Linux only when the application or test stack needs a display.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the headless flag in the browser’s WebDriver capability in wdio.conf.js, then run the WebdriverIO testrunner with npx wdio run ./wdio.conf.js. Use the flag and capability namespace for your browser: Chrome, Firefox, and Edge each have their own settings. Try native headless mode first; on Linux, use Xvfb when the application or test stack depends on a display server or desktop behavior. WebdriverIO defines a headless browser as one running “without window or UI.”

Configure headless mode for your browser

Put the browser’s headless argument inside its vendor-specific options object in the capability. Do not copy one browser’s options namespace or flag to another.

As an Amazon Associate I earn from qualifying purchases.

Chrome or Chromium

export const config = {
  capabilities: [{
    browserName: 'chrome',
    'goog:chromeOptions': {
      args: ['--headless=new', '--no-sandbox']
    }
  }]
}

Use browserName: 'chromium' if that is the browser name configured for your environment. The documented Chrome example includes --no-sandbox; treat it as an environment-specific flag, not a universal security recommendation. In a container, assess the image’s security model before using it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Firefox

export const config = {
  capabilities: [{
    browserName: 'firefox',
    'moz:firefoxOptions': {
      args: ['-headless']
    }
  }]
}

Microsoft Edge

export const config = {
  capabilities: [{
    browserName: 'msedge',
    'ms:edgeOptions': {
      args: ['--headless']
    }
  }]
}

These examples follow the WebdriverIO capabilities guide. It says Safari does not support headless execution. Browser flags and behavior can change across releases, so check the browser and WebdriverIO versions used by your project.

Run the tests

Once the capability is configured, run the testrunner from the project directory:

npx wdio run ./wdio.conf.js

To isolate a startup problem or a failing test, run one spec file:

npx wdio run ./wdio.conf.js --spec example.e2e.js

The getting started guide documents the --spec option. Replace the example path with a spec file in your project.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose native headless mode or Xvfb

Use native headless mode first

Native headless mode is the simplest route when the browser, application, and test tooling work without a desktop session. Start with the browser-specific arguments above and add Xvfb only if the environment requires a display.

Use Xvfb for display-dependent Linux runs

Xvfb provides a virtual display on Linux. Consider it when the application or test stack expects DISPLAY, a window manager, GLX, or other desktop behavior—for example, some Electron tests. WebdriverIO’s Headless & Xvfb guide describes how the testrunner considers Xvfb when DISPLAY is absent or headless browser flags are passed.

The relevant settings have distinct purposes:

  • autoXvfb controls whether WebdriverIO wraps a worker with Xvfb. Set it deliberately; autoXvfb: false disables the automatic behavior.
  • If CI already provides an X server, export its DISPLAY value so the runner can use it, or explicitly disable automatic Xvfb if that fits the setup.
  • xvfbAutoInstall relates to installing Xvfb if xvfb-run is missing. It does not itself turn on Xvfb use.

For example, a configuration may combine automatic Xvfb handling with Chrome’s headless arguments:

export const config = {
  autoXvfb: true,
  capabilities: [{
    browserName: 'chrome',
    'goog:chromeOptions': {
      args: ['--headless=new', '--no-sandbox']
    }
  }]
}

Only enable automatic package installation when the CI image and its permissions make that appropriate. The guide’s Docker example installs xvfb on Ubuntu or Debian with apt-get; other distributions use different package names and installers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check browser and driver setup in CI or Docker

A headless flag cannot fix a browser binary that is missing or a driver that cannot start it. Before diagnosing a test assertion, verify the browser and driver are available in the execution environment. WebdriverIO can locate or install supported browsers and drivers under documented conditions; if automatic discovery does not find the browser, its driver binaries guide shows how to specify a binary path with goog:chromeOptions.binary or moz:firefoxOptions.binary.

For Docker, WebdriverIO’s Docker guide demonstrates Chrome arguments including --no-sandbox, --disable-gpu, and a window-size flag. These are example settings to adapt—not a requirement that every container use the same flags. Keep the installed Chrome version aligned with the ChromeDriver version configured for the image, and pin compatible versions in the project’s environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot failed headless runs

  1. Session creation fails immediately: Confirm the browser is installed or configured, the capability has the correct browserName, and the options use the matching vendor namespace. If necessary, set the browser binary path.
  2. The browser opens with a visible window or rejects the option: Check that the flag is spelled for that browser and placed inside its args array. Chrome, Firefox, and Edge do not share identical flags.
  3. It works locally but fails in Docker: Check that the browser and driver versions match, that the binary exists in the image, and that any container-specific flags reflect the image’s security and graphics setup.
  4. The application behaves differently or cannot start: Determine whether it depends on DISPLAY, a window manager, GLX, or desktop behavior. On Linux, check whether CI already supplies Xvfb and whether autoXvfb should be enabled or disabled.
  5. Xvfb does not start: Check whether xvfb-run is installed and review the WebdriverIO guide’s retry and troubleshooting options. Avoid automatic installation in locked-down CI unless package installation is permitted and intended.
  6. The log mentions DevToolsActivePort or a user-data-directory collision: WebdriverIO notes these messages may follow a browser crash and restart. Investigate the initial browser launch and environment first rather than assuming the profile directory is the root cause.
  7. You need to separate setup from test behavior: Rerun one spec with npx wdio run ./wdio.conf.js --spec example.e2e.js, then expand back to the full suite once the browser starts reliably.

Or skip the browser setup

If your immediate need is a screenshot or PDF of a page rather than an interactive WebdriverIO test, ScreenshotNeo offers a one-request website capture API. Its API documentation covers the request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes 60+ known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers indicate the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.