11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4+ using Microsoft . AspNetCore . Components . E2ETest ;
45using Microsoft . AspNetCore . Components . E2ETest . Infrastructure . ServerFixtures ;
56using Microsoft . AspNetCore . Components . E2ETest . Infrastructure ;
67using Microsoft . AspNetCore . E2ETesting ;
@@ -668,7 +669,7 @@ public void CanUpdateHrefOnLinkTagWithIntegrity()
668669 [ InlineData ( false , true ) ]
669670 [ InlineData ( true , true ) ]
670671 [ InlineData ( true , false ) ]
671- public async Task EnhancedNavigationScrollBehavesSameAsFullNavigation ( bool enableStreaming , bool useEnhancedNavigation )
672+ public void EnhancedNavigationScrollBehavesSameAsFullNavigation ( bool enableStreaming , bool useEnhancedNavigation )
672673 {
673674 // This test checks if the navigation to other path moves the scroll to the top of the page,
674675 // or to the beginning of a fragment, regardless of the previous scroll position,
@@ -683,6 +684,7 @@ public async Task EnhancedNavigationScrollBehavesSameAsFullNavigation(bool enabl
683684 var elementForStalenessCheckOnScrollPage = Browser . Exists ( By . TagName ( "html" ) ) ;
684685
685686 var jsExecutor = ( IJavaScriptExecutor ) Browser ;
687+ WaitFullPageLoaded ( ) ;
686688 var maxScrollPosition = ( long ) jsExecutor . ExecuteScript ( "return document.documentElement.scrollHeight - window.innerHeight;" ) ;
687689
688690 // scroll maximally down and go to another page - we should land at the top of that page
@@ -693,11 +695,7 @@ public async Task EnhancedNavigationScrollBehavesSameAsFullNavigation(bool enabl
693695 Assert . Equal ( 0 , Browser . GetScrollY ( ) ) ;
694696 var elementForStalenessCheckOnHashPage = Browser . Exists ( By . TagName ( "html" ) ) ;
695697
696- if ( enableStreaming )
697- {
698- // wait for the fragment to be visible - let the streaming finish
699- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
700- }
698+ WaitFullPageLoaded ( ) ;
701699 var fragmentScrollPosition = ( long ) jsExecutor . ExecuteScript ( "return Math.round(document.getElementById('some-content').getBoundingClientRect().top + window.scrollY);" ) ;
702700
703701 // go back and check if the scroll position is preserved
@@ -708,25 +706,15 @@ public async Task EnhancedNavigationScrollBehavesSameAsFullNavigation(bool enabl
708706 // parts of page conditioned with showContent are showing with a delay - it affect the scroll position
709707 // from some reason, scroll position differs by 1 pixel between enhanced and browser's navigation
710708 var expectedMaxScrollPositionAfterBackwardsAction = useEnhancedNavigation ? maxScrollPosition : maxScrollPosition - 1 ;
711- if ( enableStreaming )
712- {
713- // let the streaming finish
714- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
715- expectedMaxScrollPositionAfterBackwardsAction = maxScrollPosition + 127 ; // why 127 ???
716- expectedMaxScrollPositionAfterBackwardsAction = useEnhancedNavigation ? expectedMaxScrollPositionAfterBackwardsAction : expectedMaxScrollPositionAfterBackwardsAction - 1 ;
717- }
709+ WaitFullPageLoaded ( ) ;
718710 Assert . Equal ( expectedMaxScrollPositionAfterBackwardsAction , Browser . GetScrollY ( ) ) ;
719711
720712 // navigate to a fragment on another page - we should land at the beginning of the fragment
721713 Browser . Exists ( By . Id ( "do-navigation-with-fragment" ) ) . Click ( ) ;
722714 AssertWeAreOnHashPage ( ) ;
723715 AssertEnhancedNavigationOnHashPage ( ) ;
724716 var expectedFragmentScrollPosition = fragmentScrollPosition - 1 ;
725- if ( enableStreaming )
726- {
727- // let the streaming finish
728- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
729- }
717+ WaitFullPageLoaded ( ) ;
730718 Assert . Equal ( expectedFragmentScrollPosition , Browser . GetScrollY ( ) ) ;
731719
732720 // go back to be able to go forward and check if the scroll position is preserved
@@ -737,6 +725,7 @@ public async Task EnhancedNavigationScrollBehavesSameAsFullNavigation(bool enabl
737725 Browser . Navigate ( ) . Forward ( ) ;
738726 AssertWeAreOnHashPage ( ) ;
739727 AssertEnhancedNavigationOnHashPage ( ) ;
728+ WaitFullPageLoaded ( ) ;
740729 Assert . Equal ( expectedFragmentScrollPosition , Browser . GetScrollY ( ) ) ;
741730
742731 void AssertEnhancedNavigationOnHashPage ( ) =>
@@ -765,6 +754,14 @@ void AssertWeAreOnHashPage()
765754 {
766755 Browser . Equal ( "Scroll to hash" , ( ) => Browser . Exists ( By . Id ( "test-info" ) ) . Text ) ;
767756 }
757+
758+ void WaitFullPageLoaded ( )
759+ {
760+ if ( enableStreaming )
761+ {
762+ Browser . WaitForElementToBeVisible ( By . Id ( "some-content" ) ) ;
763+ }
764+ }
768765 }
769766
770767 private void AssertEnhancedUpdateCountEquals ( long count )
0 commit comments