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

Code before:
        var dispatchToForm = new DispatchToForm(this)
        {
            Url = "forms/default-form-bound-parameter",
            FormCssSelector = "form",
            InputFieldId = "Parameter",
            InputFieldCssSelector = "input[name=Parameter]",
            InputFieldValue = "stranger",
            SuppressEnhancedNavigation = suppressEnhancedNavigation,
        };
        DispatchToFormCore(dispatchToForm);
    }

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void InputHiddenCanStoreData(bool suppressEnhancedNavigation)
    {
        var dispatchToForm = new DispatchToForm(this)
        {
            Url = "forms/default-form-input-hidden",
            FormCssSelector = "form",
            SuppressEnhancedNavigation = suppressEnhancedNavigation,
        };
        DispatchToFormCore(dispatchToForm);
        var textHidden = Browser.Exists(By.Id("hidden")).GetDomProperty("value");
        Assert.Equal("stranger", textHidden);
        var textPass = Browser.Exists(By.Id("pass")).Text;
        Assert.Equal("Hello stranger!", textPass);
    }

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void DataAnnotationsWorkForForms(bool suppressEnhancedNavigation)
    {
        var dispatchToForm = new DispatchToForm(this)
        {
            Url = "forms/default-form-bound-parameter-annotations",
            FormCssSelector = "form",
            InputFieldId = "Parameter.FirstName",
            InputFieldCssSelector = "input[name='Parameter.FirstName']",
            InputFieldValue = "John",
            SuppressEnhancedNavigation = suppressEnhancedNavigation,
            ErrorSelector = "ul.validation-errors li.validation-message",
            AssertErrors = errors =>
            {
                var error = Assert.Single(errors);
                Assert.Equal("Name is too long", error.Text);
                Assert.Equal("John", Browser.FindElement(By.CssSelector("input[name='Parameter.FirstName']")).GetDomProperty("value"));
            },
        };

Review comment (suggestion):
This is fine but to make sure Selenium does not execute this check before the element is in the DOM, let's use a check that waits for the element with some default timeout, like here:

https://github.com/dariatiurina/aspnetcore/blob/e8fb9aa5e1437470c4a88c6ef3c8101c14df1529/src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/FormWithParentBindingContextTest.cs#L1568


Code after:
        var dispatchToForm = new DispatchToForm(this)
        {
            Url = "forms/default-form-bound-parameter",
            FormCssSelector = "form",
            InputFieldId = "Parameter",
            InputFieldCssSelector = "input[name=Parameter]",
            InputFieldValue = "stranger",
            SuppressEnhancedNavigation = suppressEnhancedNavigation,
        };
        DispatchToFormCore(dispatchToForm);
    }

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void InputHiddenCanStoreData(bool suppressEnhancedNavigation)
    {
        var dispatchToForm = new DispatchToForm(this)
        {
            Url = "forms/default-form-input-hidden",
            FormCssSelector = "form",
            SuppressEnhancedNavigation = suppressEnhancedNavigation,
        };
        DispatchToFormCore(dispatchToForm);

        Browser.Equal("stranger", () => Browser.Exists(By.Id("hidden")).GetDomProperty("value"));
        Browser.Equal("Hello stranger!", () => Browser.Exists(By.Id("pass")).Text);
    }

    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void DataAnnotationsWorkForForms(bool suppressEnhancedNavigation)
    {
        var dispatchToForm = new DispatchToForm(this)
        {
            Url = "forms/default-form-bound-parameter-annotations",
            FormCssSelector = "form",
            InputFieldId = "Parameter.FirstName",
            InputFieldCssSelector = "input[name='Parameter.FirstName']",
            InputFieldValue = "John",
            SuppressEnhancedNavigation = suppressEnhancedNavigation,
            ErrorSelector = "ul.validation-errors li.validation-message",
            AssertErrors = errors =>
            {
                var error = Assert.Single(errors);
                Assert.Equal("Name is too long", error.Text);
                Assert.Equal("John", Browser.FindElement(By.CssSelector("input[name='Parameter.FirstName']")).GetDomProperty("value"));
            },
        };
        DispatchToFormCore(dispatchToForm);