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

Code before:
using System.Net.Http;
using System.Text;
using Components.TestServer.RazorComponents;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using Microsoft.AspNetCore.InternalTesting;
using OpenQA.Selenium;
using TestServer;
using Xunit.Abstractions;

namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.FormHandlingTests;

public class FormWithNoBackForwardCacheTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>>
{
    public FormWithNoBackForwardCacheTest(
        BrowserFixture browserFixture,
        BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
        ITestOutputHelper output)
        : base(browserFixture, serverFixture, output)
    {
    }

    public override Task InitializeAsync()
    {
        return InitializeAsync(BrowserFixture.BackForwardCacheContext);
    }

    private void SuppressEnhancedNavigation(bool shouldSuppress)
        => EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress);

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void CanUseFormWithMethodGet(bool suppressEnhancedNavigation)
    {
        SuppressEnhancedNavigation(suppressEnhancedNavigation);
        Navigate($"{ServerPathBase}/forms/method-get");
        Browser.Equal("Form with method=get", () => Browser.FindElement(By.TagName("h2")).Text);

        // Validate initial state
        var stringInput = Browser.FindElement(By.Id("mystring"));
        var boolInput = Browser.FindElement(By.Id("mybool"));
        Browser.Equal("Initial value", () => stringInput.GetDomProperty("value"));
        Browser.Equal("False", () => boolInput.GetDomProperty("checked"));

        // Edit and submit the form; check it worked
        stringInput.Clear();
        stringInput.SendKeys("Edited value");
        boolInput.Click();
        Browser.FindElement(By.Id("submit-get-form")).Click();

Review comment (performance):
This overrides `BrowserFixture.StreamingContext`. I know you wanted the flag to be passed but we have to keep `streaming` in the browser context, it affects how we load the page (we have the `None` policy activated with streaming, otherwise it's `Normal`).
We have 2 options:
1) Check who else is using streaming context and assess how many tests would run with the outdated settings if we added cache fallback to all of them by default, then move this test back to the original class and add the cache fallback flag for streaming.
2) Have a separate context `StreamingBackForwardCacheContext` that would activate both features.

Code after:
using System.Net.Http;
using System.Text;
using Components.TestServer.RazorComponents;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using Microsoft.AspNetCore.InternalTesting;
using OpenQA.Selenium;
using TestServer;
using Xunit.Abstractions;

namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.FormHandlingTests;

public class FormWithNoBackForwardCacheTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>>
{
    public FormWithNoBackForwardCacheTest(
        BrowserFixture browserFixture,
        BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
        ITestOutputHelper output)
        : base(browserFixture, serverFixture, output)
    {
    }

    public override Task InitializeAsync()
    {
        return InitializeAsync(BrowserFixture.StreamingBackForwardCacheContext);
    }

    private void SuppressEnhancedNavigation(bool shouldSuppress)
        => EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress);

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void CanUseFormWithMethodGet(bool suppressEnhancedNavigation)
    {
        SuppressEnhancedNavigation(suppressEnhancedNavigation);
        Navigate($"{ServerPathBase}/forms/method-get");
        Browser.Equal("Form with method=get", () => Browser.FindElement(By.TagName("h2")).Text);

        // Validate initial state
        var stringInput = Browser.FindElement(By.Id("mystring"));
        var boolInput = Browser.FindElement(By.Id("mybool"));
        Browser.Equal("Initial value", () => stringInput.GetDomProperty("value"));
        Browser.Equal("False", () => boolInput.GetDomProperty("checked"));

        // Edit and submit the form; check it worked
        stringInput.Clear();
        stringInput.SendKeys("Edited value");
        boolInput.Click();
        Browser.FindElement(By.Id("submit-get-form")).Click();