Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsTo add Angular component harness support to a testing environment beyond TestBed or WebDriver, implement two bindings: a TestElement that performs interactions using that environment, and a concrete HarnessEnvironment that connects element lookup and Angular stability to it. Add a static loader so test code can obtain harnesses, and connect automatic change-detection status if the environment must support manualChangeDetection or parallel.
This guidance follows Angular’s documentation as accessed October 7, 2026, which identified the site as v22.2.1. Check the current API before implementing against a different Angular version.
As an Amazon Associate I earn from qualifying purchases.
When should you add a custom harness environment?
Angular CDK supplies harness environments for unit tests using Angular TestBed and end-to-end tests using Selenium WebDriver. Use the supplied loader when your tests run in one of those environments. For another runner or browser automation setup, you need to define how it represents and interacts with DOM elements, then bind those operations to the harness API. Angular’s guide begins with installing the CDK using ng add @angular/cdk.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Component harnesses let tests interact with a component through a supported API intended to resemble user interaction. This can make tests less dependent on private details such as a component’s DOM structure, improve readability and maintenance, and allow a harness to be reused across environments. That reuse is particularly useful for shared interactive components that may change independently from the applications using them. Angular Material provides harnesses for its components.
#1 Best Overall
What the built-in loaders provide
The root and scope available to a test vary by environment, so decide how your custom loader should expose them.
- TestBed:
TestbedHarnessEnvironmentis normally rooted at aComponentFixture. ItsdocumentRootLoader()can locate elements outside the fixture, such as overlays or popups appended todocument.body. UseharnessForFixture()when you need a harness for the fixture root itself. - Selenium WebDriver:
SeleniumWebDriverHarnessEnvironmenttakes a WebDriver client and is rooted at the current document.
These are useful reference implementations for understanding the relationship between a loader, a scoped environment, and the target environment’s element operations.
Rank #2
Implement the environment-specific TestElement
Every environment must define a TestElement implementation. It wraps the target environment’s representation of an element and supplies the interactions harnesses expect, such as blur(), click(), and getAttribute(). These methods return promises, keeping the harness API usable with environments where DOM operations are asynchronous, including WebDriver.
Pay particular attention to keyboard input. The target runner’s key codes may not match the CDK’s TestKey values, so map CDK keys to the target environment’s codes rather than assuming they are interchangeable. Angular recommends examining the CDK’s unit-test and Selenium WebDriver element implementations as examples.
Rank #3
Subclass HarnessEnvironment
In HarnessEnvironment<E>, E is the raw element type used by your target environment. The subclass implements six abstract members to connect that type to harness lookup and Angular’s stability model:
| Member | What your implementation must do |
|---|---|
getDocumentRoot(): E |
Return the root element for the environment, such as document.body. |
createTestElement(element: E): TestElement |
Wrap a raw element in your environment-specific TestElement. |
createEnvironment(element: E): HarnessEnvironment |
Create a nested environment rooted at the supplied element, so harnesses can scope their searches. |
getAllRawElements(selector: string): Promise<E[]> |
Find all elements matching the selector beneath the current environment root. |
forceStabilize(): Promise<void> |
Resolve when Angular’s NgZone is stable and, where applicable, cause stabilization. Angular gives flush() in a fakeAsync test as an example. |
waitForTasksOutsideAngular(): Promise<void> |
Resolve when the parent zone of NgZone is stable. |
Give the class a protected constructor and a static loader entry point that returns a HarnessLoader. This provides the standard way for test authors to request harnesses from your environment. You can expose additional entry points or constructor arguments where your runner needs them; the TestBed environment, for example, has fixture-root and document-root access patterns.
Rank #4
Support automatic change detection where needed
If the environment should work with manualChangeDetection and the parallel APIs, connect it to automatic change-detection status handling. Call handleAutoChangeDetectionStatus(handler) to receive a status object with isDisabled and onDetectChangesNow(). Stop handling that status by calling stopHandlingAutoChangeDetectionStatus() when appropriate for the environment’s lifecycle.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteTest the behavioral differences, not just the method signatures
Harness methods are mostly asynchronous. Angular recommends using await for clarity; its parallel helper can run operations simultaneously and optimize change-detection checks. Correctly implementing the abstract members is necessary, but does not guarantee identical behavior across environments: a real user interaction and a simulated unit-test event may differ. The CDK makes a best effort to normalize behavior, not a promise that every environment produces identical events.
Validate your implementation against the characteristics that can change how a harness behaves:
- Whether DOM operations are synchronous or asynchronous.
- How clicks, keyboard input, and other events are generated, including any key-code mapping.
- Which root and scoped element access patterns the loader supports.
- How Angular change detection, zone stability, and work outside Angular are represented.
Angular documents its TestBed and Selenium WebDriver implementations as examples to study in the guide to adding harness support for additional testing environments. For the harness model and its qualitative benefits, see the component harness overview and usage guide.
Quick Recap
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.




