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

Use Selenium WebDriver with a Chrome driver, add --headless to Chrome options, start your Angular app, wait for stable rendered elements, assert the result, and always quit the driver. The same test can run on a developer machine or in CI without a display. Angular CLI’s ng e2e command can build and serve the project before invoking its configured end-to-end target; if your workspace has no target, add one or use an integration such as WebdriverIO.

What the headless Angular test setup contains

Selenium WebDriver is a language-neutral browser-control API. Chrome is controlled through a compatible browser driver, so your test environment needs all of the following:

  • An Angular workspace and a repeatable way to serve it.
  • Chrome or Chromium installed in the test environment.
  • A Selenium binding for your language (the runnable example below uses JavaScript).
  • A Chrome driver compatible with the installed browser, installed according to Selenium’s current setup model.
  • A test runner and assertions, such as Mocha, Jest, or the runner provided by your end-to-end builder.

Headless mode changes how Chrome renders, not what your test is supposed to verify. Keep the same application URL, selectors, waits, and assertions you use for a headed run; only the browser startup configuration needs the headless argument.

Prepare the Angular application

Use an existing e2e target

Inspect the workspace configuration for an e2e target. When one exists, Angular CLI’s command is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Samsung 14" Galaxy Chromebook Go Laptop PC Computer, Intel Celeron N4500 Processor, 4GB RAM, 64GB Storage, ChromeOS, XE340XDA-KA2US, Student Laptop, Silver
  • SLIM. LIGHTWEIGHT. READY TO GO: The all-new slim design is perfect for busy lives on the go.
  • SKILLFULLY DESIGNED. MILITARY TOUGH: Built with premium craftsmanship to withstand the occasional drop or ding.
  • ALL-DAY, ALL-IN-ONE CHARGING: Power through your school day – and beyond – with a long-lasting 12-hour battery.¹
  • 3X FASTER THAN THE PREVIOUS GENERATION OF WIFI: Crush your schoolwork in record time with Wi-Fi that’s three times faster than the previous generation of Wi-Fi.
  • YOUR PHONE AND CHROMEBOOK WORK BETTER TOGETHER: Easily transfer files between devices, and control your phone right from your Chromebook.
ng e2e

The CLI builds and serves the project, then runs the configured end-to-end builder. The exact test command, port, and browser setup depend on that builder. Run it once in headed mode if possible so that application startup and selectors are easy to diagnose, then enable headless Chrome for CI.

Add a target when the workspace has none

If ng e2e reports that no target exists, choose and configure an end-to-end integration supported by your Angular version. Current CLI guidance lists integrations including WebdriverIO, Playwright, Cypress, Nightwatch, and Puppeteer. The important Selenium-specific requirement remains the same: the selected test process must be able to reach the URL served by Angular and must create a compatible Chrome session.

Start the app explicitly

For a small JavaScript test suite, an explicit server command is often easiest to reason about:

ng serve --host 0.0.0.0 --port 4200

Wait until the server is accepting connections, then point Selenium at http://localhost:4200 (or the host name visible from your CI container). In a separate shell, run the test command. In CI, use a process manager or a job step that keeps the Angular server alive until the test exits.

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

Install Selenium and create a headless Chrome driver

Install the Selenium JavaScript binding in the project:

npm install --save-dev selenium-webdriver

Install Chrome/Chromium and a compatible Chrome driver in the machine image. Selenium’s setup model can manage drivers in supported environments, but the browser and driver still have to be compatible and discoverable by the process. Record the browser and driver versions in CI logs when diagnosing a session-creation failure.

Minimal runnable JavaScript test

const { Builder, By, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

(async function angularSmokeTest() {
  const options = new chrome.Options()
    .addArguments('--headless');

  const driver = await new Builder()
    .forBrowser('chrome')
    .setChromeOptions(options)
    .build();

  try {
    await driver.manage().setTimeouts({
      implicit: 0,
      pageLoad: 30000,
      script: 30000
    });

    await driver.get('http://localhost:4200');

    const heading = await driver.wait(
      until.elementLocated(By.css('[data-testid="page-heading"]')),
      15000,
      'Angular page heading was not rendered'
    );
    await driver.wait(until.elementIsVisible(heading), 5000);

    const text = await heading.getText();
    if (text !== 'Dashboard') {
      throw new Error(`Expected Dashboard, received ${text}`);
    }
  } finally {
    await driver.quit();
  }
})();

The example follows the essential lifecycle: configure timeouts, navigate, wait for a rendered control, interact or inspect it, assert the expected outcome, and call quit() in a finally block. Replace the URL, test ID, and expected text with values from your application.

Make Angular waits reliable

Wait for state, not a guessed sleep

Angular pages often render a shell before data arrives. A fixed delay such as sleep(5000) makes fast runs slower and slow runs flaky. Prefer an explicit condition:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
HP Chromebook 14 Laptop, Intel Celeron N4120, 4 GB RAM, 64 GB eMMC, 14" HD Display, Chrome OS, Thin Design, 4K Graphics, Long Battery Life, Ash Gray Keyboard (14a-na0226nr, 2022, Mineral Silver)
  • FOR HOME, WORK, & SCHOOL – With an Intel processor, 14-inch display, custom-tuned stereo speakers, and long battery life, this Chromebook laptop lets you knock out any assignment or binge-watch your favorite shows..Voltage:5.0 volts
  • HD DISPLAY, PORTABLE DESIGN – See every bit of detail on this micro-edge, anti-glare, 14-inch HD (1366 x 768) display (1); easily take this thin and lightweight laptop PC from room to room, on trips, or in a backpack.
  • ALL-DAY PERFORMANCE – Reliably tackle all your assignments at once with the quad-core, Intel Celeron N4120—the perfect processor for performance, power consumption, and value (2).
  • 4K READY – Smoothly stream 4K content and play your favorite next-gen games with Intel UHD Graphics 600 (3) (4).
  • MEMORY AND STORAGE – Enjoy a boost to your system’s performance with 4 GB of RAM while saving more of your favorite memories with 64 GB of reliable flash-based eMMC storage (5).
const saveButton = await driver.wait(
  until.elementLocated(By.css('[data-testid="save"]')),
  15000
);
await driver.wait(until.elementIsEnabled(saveButton), 5000);
await saveButton.click();

await driver.wait(
  until.elementLocated(By.css('[role="status"][data-state="saved"]')),
  15000
);

Use resilient selectors

Add stable data-testid attributes to controls whose purpose is testing. Accessibility selectors such as [role="button"] or a label-based locator can also express user-visible intent. Avoid selectors tied to Angular’s generated structure, incidental CSS classes, or an element’s position in a list.

Control implicit and explicit waits

The sample sets an implicit timeout of zero and uses explicit waits so each condition has a visible deadline. Mixing a long implicit wait with explicit waits can multiply delays when a locator is missing. Set a page-load timeout appropriate to your application and give each asynchronous state its own diagnostic message.

Test navigation and browser state deliberately

Use driver.get() for a fresh navigation. If a scenario depends on authentication, seed a test account or add cookies before navigating to the protected route; do not rely on a developer’s existing browser profile. Clear cookies between tests when isolation matters:

await driver.manage().deleteAllCookies();

Chrome options for CI

Start with only headless mode

Chrome’s official Selenium guidance enables headless mode by adding --headless before building the driver. Keep the option set minimal first. Additional flags copied from unrelated Docker examples can hide a real permission or sandbox problem.

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

Add environment-specific flags only when required

Some restricted CI images require a larger shared-memory mount or a sandbox adjustment. Treat these as responses to a documented failure in that image, not universal Selenium settings. For example, an environment that cannot use Chrome’s sandbox may need:

const options = new chrome.Options()
  .addArguments('--headless', '--no-sandbox');

Using --no-sandbox reduces browser isolation and should be limited to a controlled CI container. If Chrome crashes with shared-memory errors, increase the container’s shared memory allocation before adding workarounds that change browser behavior.

Capture useful artifacts

On failure, save a screenshot, page source, browser console output, and the test’s URL. These artifacts distinguish an Angular rendering error from a driver, network, or selector problem. Ensure the CI job uploads them even when the test command exits nonzero.

Run the test in CI without a display

  1. Install the same major Chrome/Chromium version and a compatible driver in the CI image.
  2. Install Node dependencies with the lockfile.
  3. Start Angular with a known host and port, or let the configured ng e2e builder manage the server.
  4. Wait for the health URL or port to become reachable.
  5. Run the test command with --headless in the Chrome options.
  6. Upload screenshots, logs, and page source on failure.
  7. Terminate the Angular server and let the test’s finally block call driver.quit().

Angular’s browser-testing documentation describes CI as using headless mode by default and allows explicit provider names such as chromeHeadless or chromiumHeadless. Use the name required by your configured builder; do not assume a Karma, WebdriverIO, and custom Selenium configuration share the same browser label.

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

Local Chrome versus Selenium Grid

Concern Local headless Chrome Selenium Grid or hosted service
Setup ownership You install and patch the browser, driver, and CI image. The Grid owner supplies remote nodes; you still manage test code and capabilities.
Browser and OS coverage Usually one browser/OS combination per image. Multiple browser and operating-system nodes can be addressed.
Parallel sessions Limited by the machine’s CPU, memory, and process isolation. Designed to distribute sessions across nodes.
Debug artifacts Files are local to the job unless uploaded. Depends on Grid or provider recording and retention settings.
Cost and complexity Lowest operational complexity; CI capacity is your constraint. More infrastructure or provider cost, in exchange for scale and coverage.

Start locally until navigation, waits, and assertions are deterministic. Move to Grid when browser/OS coverage or parallel capacity justifies the additional network and infrastructure failure modes. Selenium’s command-line documentation also describes remote Grid usage and hosted Selenium-compatible providers.

Troubleshooting common failures

“SessionNotCreated” or driver version mismatch

Cause: Chrome and ChromeDriver major versions are incompatible, or the driver is not on PATH.
Fix: Print both versions in CI, install a compatible pair, and verify the executable location used by the Selenium binding.

Chrome cannot start in CI

Cause: The image lacks Chrome libraries, has insufficient shared memory, or forbids the sandbox.
Fix: Use an image with all Chrome dependencies, increase shared memory, and only then apply a narrowly scoped option such as --no-sandbox when the container policy requires it.

“Element not found” immediately after navigation

Cause: Angular has rendered the shell but not the route or API data, or the test reached the wrong port.
Fix: Check the URL and server logs, wait for a stable application marker, and include the current URL and page source in failure artifacts.

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

Timeouts are intermittent

Cause: A race between an API response, animation, route transition, or overlay and the click/assertion.
Fix: Wait for the specific state you need (visible, enabled, URL changed, or status text), disable unnecessary animation in the test build, and avoid arbitrary sleeps.

The test passes locally but fails in CI

Cause: Different browser versions, viewport size, timezone, network access, base URL, or available resources.
Fix: Log environment versions, set the viewport explicitly when layout matters, use a deterministic test backend, and run the identical npm script locally and in CI.

Angular CLI says no e2e target exists

Cause: The workspace has no configured end-to-end builder.
Fix: Add an integration and target, or start the app with ng serve and run your Selenium test process separately.

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

Or skip the browser setup

For a one-off visual capture, documentation artifact, or AI workflow, ScreenshotNeo provides a website screenshot API and MCP server rather than requiring you to install Chrome and ChromeDriver. Its clean-shot pipeline accepts consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response reports the page verdict and billing status in headers.

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

One GET request returns PNG, JPEG, WebP, or PDF. See the ScreenshotNeo documentation for all options, including full-page lazy-image loading, CSS-selector element capture, dark mode, device presets, retina scale, PDF page ranges, custom CSS/JavaScript, clicks, waits, request blocking, headers/cookies, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous webhooks, bulk capture, and usage reporting.

Rank #4
HP 14" HD Chromebook Laptop for Students, Intel Quad-Core N4120(> N4020), 4GB RAM, 64GB eMMC, WiFi, Webcam, HDMI, USB-A&C, 14 Hours Battery Life, Zoom, Chrome OS, CUE Accessories
  • Intel Celeron N4120: 4 Cores & Threads, 1.1GHz Base Clock, Up to 2.6GHz Boost Clock, 4MB Cache, Intel UHD Graphics 600. The perfect combination of performance, power consumption, and value helps your device handle multitasking smoothly and reliably with four processing cores to divide up the work.
  • 14" HD Display: 14.0-inch diagonal, HD (1366 x 768), micro-edge, anti-glare. See your digital world in a whole new way. Enjoy movies and photos with the great image quality and high-definition detail of 1 million pixels.
  • Memory & Storage: 4 GB LPDDR4x & 64 GB eMMC Storage. Adequate high-bandwidth RAM to smoothly run multiple applications and browser tabs all at once. An embedded multimedia card provides reliable flash-based storage.
  • Ports:2 x USB 3.0 Type-A,1 x USB 3.0 Type-C,1 x HDMI,1 x Headphone Jack
  • Chrome OS: Chromebook is a computer for the way the modern world works, with thousands of apps. Enjoy the seamless simplicity that comes with Google Chrome and Android apps, all integrated into one laptop. It’s fast, simple, and secure.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

An MCP server supplies take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

FAQ

Does headless mode test a different Angular application?

No. It runs Chrome without a visible window. Differences can still arise from viewport, fonts, GPU, timing, and CI resources, so fix those environment variables when a layout-sensitive test matters.

Should every test create a new driver?

Isolation is safest for independent end-to-end scenarios, while reusing a session can reduce startup time. If you reuse one, explicitly reset cookies, storage, and application state between tests.

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

When should I use Grid?

Use Grid when you need multiple browser/OS combinations or more parallel sessions than one CI machine can provide. It is unnecessary overhead for a small, single-browser smoke suite.

Frequently Asked Questions

Can I run Selenium against an Angular production build?

Yes. Serve the built files from a test server and set the test URL to that server; the Selenium lifecycle and waits are unchanged.

Is a fixed viewport necessary?

Only when responsive layout or breakpoint behavior is part of the assertion. Set it explicitly in Chrome options so local and CI runs use the same dimensions.

The Bottom Line

Make the local headless run deterministic first: use a compatible Chrome/driver pair, stable selectors, condition-based waits, explicit CI startup, and guaranteed teardown. Then add Grid only for justified coverage or parallelism.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

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.