Skip to content

Commit 8536c57

Browse files
authored
Re-enable FormWithParentBindingContextTest.CanUseFormWithMethodGet (#63356)
1 parent dce2aee commit 8536c57

File tree

3 files changed

+98
-54
lines changed

3 files changed

+98
-54
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.ObjectModel;
5+
using System.Net.Http;
6+
using System.Text;
7+
using Components.TestServer.RazorComponents;
8+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
9+
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
10+
using Microsoft.AspNetCore.E2ETesting;
11+
using Microsoft.AspNetCore.InternalTesting;
12+
using OpenQA.Selenium;
13+
using TestServer;
14+
using Xunit.Abstractions;
15+
16+
namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests.FormHandlingTests;
17+
18+
public class FormWithNoBackForwardCacheTest : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>>
19+
{
20+
public FormWithNoBackForwardCacheTest(
21+
BrowserFixture browserFixture,
22+
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
23+
ITestOutputHelper output)
24+
: base(browserFixture, serverFixture, output)
25+
{
26+
}
27+
28+
public override Task InitializeAsync()
29+
{
30+
return InitializeAsync(BrowserFixture.StreamingBackForwardCacheContext);
31+
}
32+
33+
private void SuppressEnhancedNavigation(bool shouldSuppress)
34+
=> EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress);
35+
36+
[Theory]
37+
[InlineData(true)]
38+
[InlineData(false)]
39+
public void CanUseFormWithMethodGet(bool suppressEnhancedNavigation)
40+
{
41+
SuppressEnhancedNavigation(suppressEnhancedNavigation);
42+
Navigate($"{ServerPathBase}/forms/method-get");
43+
Browser.Equal("Form with method=get", () => Browser.FindElement(By.TagName("h2")).Text);
44+
45+
// Validate initial state
46+
var stringInput = Browser.FindElement(By.Id("mystring"));
47+
var boolInput = Browser.FindElement(By.Id("mybool"));
48+
Browser.Equal("Initial value", () => stringInput.GetDomProperty("value"));
49+
Browser.Equal("False", () => boolInput.GetDomProperty("checked"));
50+
51+
// Edit and submit the form; check it worked
52+
stringInput.Clear();
53+
stringInput.SendKeys("Edited value");
54+
boolInput.Click();
55+
Browser.FindElement(By.Id("submit-get-form")).Click();
56+
AssertUiState("Edited value", true);
57+
Browser.Contains($"MyString=Edited+value", () => Browser.Url);
58+
Browser.Contains($"MyBool=True", () => Browser.Url);
59+
60+
// Check 'back' correctly gets us to the previous state
61+
Browser.Navigate().Back();
62+
AssertUiState("Initial value", false);
63+
Browser.False(() => Browser.Url.Contains("MyString"));
64+
Browser.False(() => Browser.Url.Contains("MyBool"));
65+
66+
// Check 'forward' correctly recreates the edited state
67+
Browser.Navigate().Forward();
68+
AssertUiState("Edited value", true);
69+
Browser.Contains($"MyString=Edited+value", () => Browser.Url);
70+
Browser.Contains($"MyBool=True", () => Browser.Url);
71+
72+
void AssertUiState(string expectedStringValue, bool expectedBoolValue)
73+
{
74+
Browser.Equal(expectedStringValue, () => Browser.FindElement(By.Id("mystring-value")).Text);
75+
Browser.Equal(expectedBoolValue.ToString(), () => Browser.FindElement(By.Id("mybool-value")).Text);
76+
77+
// If we're not suppressing, we'll keep referencing the same elements to show they were preserved
78+
if (suppressEnhancedNavigation)
79+
{
80+
stringInput = Browser.FindElement(By.Id("mystring"));
81+
boolInput = Browser.FindElement(By.Id("mybool"));
82+
}
83+
84+
Browser.Equal(expectedStringValue, () => stringInput.GetDomProperty("value"));
85+
Browser.Equal(expectedBoolValue.ToString(), () => boolInput.GetDomProperty("checked"));
86+
}
87+
}
88+
}
89+

src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/FormWithParentBindingContextTest.cs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,59 +1369,6 @@ public void CanBindToFormWithFiles()
13691369
Assert.Equal("Total: 7", Browser.Exists(By.Id("form-collection")).Text);
13701370
}
13711371

1372-
[Theory]
1373-
// [InlineData(true)] QuarantinedTest: https://github.com/dotnet/aspnetcore/issues/61882
1374-
[InlineData(false)]
1375-
public void CanUseFormWithMethodGet(bool suppressEnhancedNavigation)
1376-
{
1377-
SuppressEnhancedNavigation(suppressEnhancedNavigation);
1378-
GoTo("forms/method-get");
1379-
Browser.Equal("Form with method=get", () => Browser.FindElement(By.TagName("h2")).Text);
1380-
1381-
// Validate initial state
1382-
var stringInput = Browser.FindElement(By.Id("mystring"));
1383-
var boolInput = Browser.FindElement(By.Id("mybool"));
1384-
Browser.Equal("Initial value", () => stringInput.GetDomProperty("value"));
1385-
Browser.Equal("False", () => boolInput.GetDomProperty("checked"));
1386-
1387-
// Edit and submit the form; check it worked
1388-
stringInput.Clear();
1389-
stringInput.SendKeys("Edited value");
1390-
boolInput.Click();
1391-
Browser.FindElement(By.Id("submit-get-form")).Click();
1392-
AssertUiState("Edited value", true);
1393-
Browser.Contains($"MyString=Edited+value", () => Browser.Url);
1394-
Browser.Contains($"MyBool=True", () => Browser.Url);
1395-
1396-
// Check 'back' correctly gets us to the previous state
1397-
Browser.Navigate().Back();
1398-
AssertUiState("Initial value", false);
1399-
Browser.False(() => Browser.Url.Contains("MyString"));
1400-
Browser.False(() => Browser.Url.Contains("MyBool"));
1401-
1402-
// Check 'forward' correctly recreates the edited state
1403-
Browser.Navigate().Forward();
1404-
AssertUiState("Edited value", true);
1405-
Browser.Contains($"MyString=Edited+value", () => Browser.Url);
1406-
Browser.Contains($"MyBool=True", () => Browser.Url);
1407-
1408-
void AssertUiState(string expectedStringValue, bool expectedBoolValue)
1409-
{
1410-
Browser.Equal(expectedStringValue, () => Browser.FindElement(By.Id("mystring-value")).Text);
1411-
Browser.Equal(expectedBoolValue.ToString(), () => Browser.FindElement(By.Id("mybool-value")).Text);
1412-
1413-
// If we're not suppressing, we'll keep referencing the same elements to show they were preserved
1414-
if (suppressEnhancedNavigation)
1415-
{
1416-
stringInput = Browser.FindElement(By.Id("mystring"));
1417-
boolInput = Browser.FindElement(By.Id("mybool"));
1418-
}
1419-
1420-
Browser.Equal(expectedStringValue, () => stringInput.GetDomProperty("value"));
1421-
Browser.Equal(expectedBoolValue.ToString(), () => boolInput.GetDomProperty("checked"));
1422-
}
1423-
}
1424-
14251372
[Fact]
14261373
public void EditFormRecursiveBinding()
14271374
{

src/Shared/E2ETesting/BrowserFixture.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class BrowserFixture : IAsyncLifetime
1515
{
1616
public static string StreamingContext { get; } = "streaming";
1717
public static string RoutingTestContext { get; } = "routing";
18+
public static string StreamingBackForwardCacheContext { get; } = "streaming.backforwardcache";
1819

1920
private readonly ConcurrentDictionary<string, (IWebDriver browser, ILogs log)> _browsers = new();
2021

@@ -142,12 +143,19 @@ private async Task DeleteBrowserUserProfileDirectoriesAsync()
142143
opts.UseWebSocketUrl = true;
143144
}
144145

145-
if (context?.StartsWith(StreamingContext, StringComparison.Ordinal) == true)
146+
if (context?.StartsWith(StreamingContext, StringComparison.Ordinal) == true || context?.StartsWith(StreamingBackForwardCacheContext, StringComparison.Ordinal) == true)
146147
{
147148
// Tells Selenium not to wait until the page navigation has completed before continuing with the tests
148149
opts.PageLoadStrategy = PageLoadStrategy.None;
149150
}
150151

152+
if (context?.StartsWith(StreamingBackForwardCacheContext, StringComparison.Ordinal) == true)
153+
{
154+
// Tells Selenium to disable the back/forward cache, which is enabled by default in Chrome.
155+
// This is needed for tests that rely on the browser's back/forward navigation.
156+
opts.AddArgument("--disable-back-forward-cache");
157+
}
158+
151159
// Force language to english for tests
152160
opts.AddUserProfilePreference("intl.accept_languages", "en");
153161

0 commit comments

Comments
 (0)