Skip to content

Conversation

ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Aug 5, 2025

Suppress enhanced navigation once per test

Enhanced navigation suppression was per page, after navigating away we were falling back to enhanced navigation, regardless of the test settings. It's because we were treating the storage as temporary measure where we were setting the suppression flag and instantly removing it after reading it in blazor start function. For tests that never navigated away (did not re-trigger blazor boot function) it was enough but for other ones, not.

Description

  • The enhanced navigation suppression flag has an id of test appended. It's unique per test instance.
  • To avoid usage of the same test id by multiple tests, we always try to clean the session storage from it on disposal.
  • Consecutive navigations in the test will run with same settings as the first page load.
  • This PR fixed order of actions: we should navigate to a page only after the suppression method got called.
  • It also enabled tests that got disabled because of issues with enhanced navigation suppression.
  • Session storage has to be available if we want to suppress enhanced navigation. If a developer wrote a test that is not navigating to any page and chose to skip the automatic navigation in EnhancedNavigationTestUtil.SuppressEnhancedNavigation, they will get an exception like:
Failed to read the 'sessionStorage' property from 'Window': Access 

SuppressEnhancedNavigation appends to the exception message an instruction how to fix this situation.

  • To be able to clean the sessionStorage, we have to have access to it. It's accessible only on loaded pages, so we chose the index page as the secure place for conducting the cleanup. To assure we're at the correct location we're checking for "Hello" h1 tag. Tests that use BasicTestApp did not have that h1 element, this PR adds it. At the same time, this PR is changing expectations of BasicTestApp-based tests - they used to look for h1 that was embedded in <app> element. The search criteria got more precise.

Fixes #60875

@ilonatommy ilonatommy force-pushed the improve-enhanced-nav-supression branch from 604e029 to 8c5c3b1 Compare August 21, 2025 07:57
@ilonatommy ilonatommy added this to the 10.0-rc2 milestone Aug 21, 2025
@ilonatommy ilonatommy marked this pull request as ready for review August 25, 2025 10:43
@Copilot Copilot AI review requested due to automatic review settings August 25, 2025 10:43
@ilonatommy ilonatommy requested a review from a team as a code owner August 25, 2025 10:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves enhanced navigation suppression in tests by making it persistent per test instance rather than per page. The changes address issues where enhanced navigation suppression was being lost after navigating away from a page, causing tests to fall back to enhanced navigation unexpectedly.

Key changes:

  • Enhanced navigation suppression now uses test-specific IDs to maintain state across navigations
  • Automatic cleanup of suppression flags when tests complete to prevent interference between tests
  • Re-enabled previously disabled tests that were affected by navigation suppression issues

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
BrowserTestBase.cs Made DisposeAsync virtual to allow overriding for cleanup
Root.razor Updated to use test-specific suppression keys and removed immediate cleanup
App.razor Updated to use test-specific suppression keys and removed immediate cleanup
EnhancedNavigationTestUtil.cs Added test ID generation, improved error handling, and cleanup functionality
EnhancedNavigationTest.cs Re-enabled quarantined tests and improved test order/cleanup
ServerTestBase.cs Added automatic cleanup of navigation suppression on test disposal

@@ -1,6 +1,9 @@
@using Microsoft.AspNetCore.Components.Rendering
@using System.Web
@inject NavigationManager NavigationManager

<h1>Hello</h1>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used in the enhanced navigation suppression method to check if session storage has conditions to get cleaned properly (page got loaded).

@javiercn javiercn added the tell-mode Indicates a PR which is being merged during tell-mode label Aug 25, 2025
@ilonatommy
Copy link
Member Author

One more thing to fix - the less frequent failure that happens when using GetElementPositionWithRetry:

 Failed Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.EnhancedNavigationTest.EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(enableStreaming: True, useEnhancedNavigation: True, programmaticNavigation: True) [4 s]
  Error Message:
   System.Exception : Failed to execute script to get position for element 'do-programmatic-navigation' after 3 retries. Debug log: Attempt 1: JavaScriptException - javascript error: Cannot read properties of null (reading 'getBoundingClientRect')
  (Session info: chrome=139.0.7258.66). Attempt 2: JavaScriptException - javascript error: Cannot read properties of null (reading 'getBoundingClientRect')
  (Session info: chrome=139.0.7258.66). Attempt 3: JavaScriptException - javascript error: Cannot read properties of null (reading 'getBoundingClientRect')
  (Session info: chrome=139.0.7258.66). 
  Stack Trace:
     at Microsoft.AspNetCore.Components.E2ETest.WebDriverExtensions.GetElementPositionWithRetry(IWebDriver browser, String elementId, Int32 retryCount, Int32 delayBetweenRetriesMs) in /home/vsts/work/1/s/src/Components/test/E2ETest/Infrastructure/WebDriverExtensions/WebDriverExtensions.cs:line 74
   at Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.EnhancedNavigationTest.EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(Boolean enableStreaming, Boolean useEnhancedNavigation, Boolean programmaticNavigation) in /home/vsts/work/1/s/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs:line 707
   at InvokeStub_EnhancedNavigationTest.EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

…rease timeouts for landing page assert that can be too short once in every 20 runs.
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 tell-mode Indicates a PR which is being merged during tell-mode test-fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quarantine EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation
2 participants