Repository: dotnet/aspnetcore
File: src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs (C#)

Code before:
    public void EnhancedNavigationScrollBehavesSameAsBrowserOnBackwardsForwardsAction(bool enableStreaming, bool useEnhancedNavigation)
    {
        // This test checks if the scroll position is preserved after backwards/forwards action
        string landingPageSuffix = enableStreaming ? "" : "-no-streaming";
        Navigate($"{ServerPathBase}/nav/testing-scroll{landingPageSuffix}");
        EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress: !useEnhancedNavigation, skipNavigation: true);

        // "scroll" page: scroll to pos1, navigate away
        AssertWeAreOnScrollTestPage();
        WaitStreamingRendersFullPage(enableStreaming);

        // staleness check is used to assert enhanced navigation is enabled/disabled, as requested
        var elementForStalenessCheckOnHashPage = Browser.Exists(By.TagName("html"));

        var jsExecutor = (IJavaScriptExecutor)Browser;
        var scrollPagePos1 = (long)jsExecutor.ExecuteScript("return Math.round(document.getElementById('do-navigation').getBoundingClientRect().top + window.scrollY);") - 100;
        Browser.SetScrollY(scrollPagePos1);
        Browser.Exists(By.Id("do-navigation")).Click();

        // "hash" page: scroll to pos1, navigate away
        WaitStreamingRendersFullPage(enableStreaming);
        AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnHashPage);
        AssertWeAreOnHashPage();
        var elementForStalenessCheckOnScrollPage = Browser.Exists(By.TagName("html"));
        var hashPagePos1 = (long)jsExecutor.ExecuteScript("return Math.round(document.getElementById('do-navigation').getBoundingClientRect().top + window.scrollY);") - 100;
        // make sure we are expecting different scroll positions on thr 1st and the 2nd page
        Assert.NotEqual(scrollPagePos1, hashPagePos1);
        Browser.SetScrollY(hashPagePos1);
        Browser.Exists(By.Id("do-navigation")).Click();

        // "scroll" page: scroll to pos2, go backwards
        AssertWeAreOnScrollTestPage();
        WaitStreamingRendersFullPage(enableStreaming);
        AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnScrollPage);
        var scrollPagePos2 = 500;
        Browser.SetScrollY(scrollPagePos2);
        Browser.Navigate().Back();

        // "hash" page: check if we landed on pos1, move the scroll to pos2, go backwards
        AssertWeAreOnHashPage();
        WaitStreamingRendersFullPage(enableStreaming);
        AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnHashPage);
        // from some reason, scroll position differs by 1 pixel between enhanced and browser's navigation
        // browser's navigation is not precisely going backwards/forwards to the previous state
        var expectedHashPagePos1 = useEnhancedNavigation ? hashPagePos1 : hashPagePos1 - 1;
        Assert.Equal(expectedHashPagePos1, Browser.GetScrollY());
        var hashPagePos2 = 600;
        Browser.SetScrollY(hashPagePos2);
        Browser.Navigate().Back();

        // "scroll" page: check if we landed on pos1, move the scroll to pos3, go forwards

Review comment (suggestion):
The comment has a typo: 'thr' should be 'the'.
```suggestion
        // make sure we are expecting different scroll positions on the 1st and the 2nd page
```

Code after:
        var expectedFragmentScrollPosition = fragmentScrollPosition - 1;
        Assert.Equal(expectedFragmentScrollPosition, Browser.GetScrollY());
    }

    [Theory]
    [InlineData(false, false, false)]
    [InlineData(false, true, false)]
    [InlineData(true, true, false)]
    [InlineData(true, false, false)]
    // [InlineData(false, false, true)] programmatic navigation doesn't work without enhanced navigation
    [InlineData(false, true, true)]
    [InlineData(true, true, true)]
    // [InlineData(true, false, true)] programmatic navigation doesn't work without enhanced navigation
    public void EnhancedNavigationScrollBehavesSameAsBrowserOnBackwardsForwardsAction(bool enableStreaming, bool useEnhancedNavigation, bool programmaticNavigation)
    {
        // This test checks if the scroll position is preserved after backwards/forwards action
        string landingPageSuffix = enableStreaming ? "" : "-no-streaming";
        string buttonKeyword = programmaticNavigation ? "-programmatic" : "";
        Navigate($"{ServerPathBase}/nav/scroll-test{landingPageSuffix}");
        EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress: !useEnhancedNavigation, skipNavigation: true);

        // "landing" page: scroll to pos1, navigate away
        AssertWeAreOnLandingPage();
        WaitStreamingRendersFullPage(enableStreaming);

        // staleness check is used to assert enhanced navigation is enabled/disabled, as requested
        var elementForStalenessCheckOnNextPage = Browser.Exists(By.TagName("html"));

        var buttonId = $"do{buttonKeyword}-navigation";
        Browser.WaitForElementToBeVisible(By.Id(buttonId));
        var landingPagePos1 = Browser.GetElementPositionWithRetry(buttonId) - 100;
        Browser.SetScrollY(landingPagePos1);
        Browser.Exists(By.Id(buttonId)).Click();

        // "next" page: scroll to pos1, navigate away
        AssertWeAreOnNextPage();
        WaitStreamingRendersFullPage(enableStreaming);
        Browser.WaitForElementToBeVisible(By.Id(buttonId));
        AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnNextPage);
        var elementForStalenessCheckOnLandingPage = Browser.Exists(By.TagName("html"));
        var nextPagePos1 = Browser.GetElementPositionWithRetry(buttonId) - 100;
        // make sure we are expecting different scroll positions on the 1st and the 2nd page
        Assert.NotEqual(landingPagePos1, nextPagePos1);
        Browser.SetScrollY(nextPagePos1);
        Browser.Exists(By.Id(buttonId)).Click();

        // "landing" page: scroll to pos2, go backwards
        AssertWeAreOnLandingPage();
        WaitStreamingRendersFullPage(enableStreaming);
        AssertEnhancedNavigation(useEnhancedNavigation, elementForStalenessCheckOnLandingPage);
        var landingPagePos2 = 500;