ExpectedConditions on Angular 2+ apps: Is Protractor’s sync reliable?
0 reputation · 01 Mar 2024, 06:30 UTC
0 reputation · 01 Mar 2024, 06:30 UTC
Developers want to use Protractor’s ExpectedConditions to wait for elements in an Angular 2+ application. The assumption is that the condition will only resolve when the Angular framework has finished rendering the target element.
$browser.waitForAngular() relies on AngularJS digest hooks that are absent in Angular 2+ (Ivy).browser.waitForAngularEnabled(true) is used, tests often hang or fail to locate elements on Angular 2+ pages.browser.waitForAngularEnabled(false) allows ExpectedConditions to work, but requires manual management and can introduce flakiness if the flag is not toggled correctly between tests.Should Protractor maintain a separate synchronization path for Angular 2+ applications, or should it continue to rely on the developer to manually disable sync and manage waits?
ExpectedConditions on an Angular 2+ page, does the condition guarantee that the page has finished rendering the target element, or does it only check the element’s current state?waitForAngularEnabled across a test suite that includes both AngularJS and Angular 2+ pages to avoid cross‑test flakiness?32775 reputation · 01 Mar 2024, 09:21 UTC
When you use ExpectedConditions on an Angular 2+ page, the condition only verifies the current state of the DOM element. It does not wait for Angular’s rendering or lifecycle hooks to finish. Protractor’s built‑in waitForAngular is designed for AngularJS and will time‑out on Angular 2+ unless you disable it. A dedicated Angular 2+ sync path is not part of current Protractor releases; manual waits with ExpectedConditions are the reliable approach.
waitForAngular relies on AngularJS digest hooks that Angular 2+ does not expose. Therefore browser.waitForAngularEnabled(true) often causes hangs or failures on modern apps.beforeEach(() => {
browser.waitForAngularEnabled(false);
});
afterEach(() => {
browser.waitForAngularEnabled(true);
});
EC.elementToBeClickable or EC.visibilityOf for interactions, but be aware that these only guarantee the element’s current visibility, not that the component’s logic is complete.Do your Angular 2+ pages use a custom zone.js patch or an external library that attempts to expose a stability signal to Protractor? If so, the recommendation may change.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.