Skip to content

Stabilize CanDisplayBindingErrorsCollectionsToDefaultForm flaky test - #68056

Merged
ilonatommy merged 4 commits into
dotnet:mainfrom
irfanajaffer:68021_FlakyTest
Jul 28, 2026
Merged

ilonatommy merged 4 commits into
dotnet:mainfrom
irfanajaffer:68021_FlakyTest

Conversation

@irfanajaffer

@irfanajaffer irfanajaffer commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Stabilize FormWithParentBindingContextTest.CanDisplayBindingErrorsCollectionsToDefaultForm

Description

This PR addresses flakiness in FormWithParentBindingContextTest.CanDisplayBindingErrorsCollectionsToDefaultForm.

The test could intermittently fail with StaleElementReferenceException during form submission and validation rendering. When the form is submitted with invalid values, Blazor rerenders the validation UI to display binding errors. During this rerender, existing validation message elements are removed and recreated. As a result, Selenium can occasionally attempt to access DOM elements that have already been replaced, causing stale element failures.

To make the test more resilient, the assertions have been updated to use retryable Browser.Contains(...), Browser.Equal(...), and Browser.True(...) assertions with DOM queries performed inside the assertion delegate. This allows the test framework to retry until the expected UI state is reached while resolving fresh DOM elements on each poll.

The updated assertions explicitly wait for:

  • The expected validation messages to be rendered after form submission.
  • The validation message collection to reach the expected count after rerendering completes.
  • The form state to reach its expected post-submit state before validation occurs.

This follows the same stabilization pattern used in PR #67677 by avoiding interactions with potentially stale element references and validating the UI only after rendering has completed.

With these changes in place, the test no longer relies on element references captured before a rerender and is resilient to transient rendering timing variations.


Validation / Investigation

As part of the investigation:

  1. The failure was analyzed and determined to be caused by a timing window between locating validation elements and asserting against them after a Blazor rerender.
  2. The test flow was reviewed to identify interactions that could occur against stale Selenium element references.
  3. The assertions were updated to use retryable browser helpers that perform fresh DOM lookups on each retry attempt.
  4. The solution aligns with an existing stabilization pattern already used for similar rerender-related test failures.
    While the issue is timing-dependent and occurs during UI rerendering, the updated assertions eliminate the stale-element window by validating against newly queried elements on every retry.

Changes

  1. Replaced validation checks with retryable Browser.Contains(...), Browser.Equal(...), and Browser.True(...) assertions.
  2. Moved DOM lookups inside assertion delegates to ensure fresh Selenium element references are obtained on every retry.
  3. Updated validation message assertions to wait for the expected binding-error messages to appear before validation succeeds.
  4. Added validation message count verification using retryable assertions to ensure rerender completion before evaluation.

Fixes #68021.

@irfanajaffer
irfanajaffer requested a review from a team as a code owner July 28, 2026 07:11
@ilonatommy ilonatommy changed the title 68021 flaky test Stabilize CanDisplayBindingErrorsCollectionsToDefaultForm flaky test Jul 28, 2026
@ilonatommy
ilonatommy enabled auto-merge (squash) July 28, 2026 08:32
@ilonatommy ilonatommy added this to the 11.0-rc1 milestone Jul 28, 2026
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components test-fixed labels Jul 28, 2026
@ilonatommy
ilonatommy merged commit 0aa2e10 into dotnet:main Jul 28, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components test-fixed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quarantine FormWithParentBindingContextTest.CanDisplayBindingErrorsCollectionsToDefaultForm

2 participants