Skip to content

Commit 047bd95

Browse files
committed
ID is not necessary if we're cleaning and not creating it for every test.
1 parent 860752c commit 047bd95

File tree

4 files changed

+7
-41
lines changed

4 files changed

+7
-41
lines changed

src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -847,20 +847,9 @@ private void AssertEnhancedNavigation(bool useEnhancedNavigation, IWebElement el
847847
{
848848
var logs = Browser.GetBrowserLogs(LogLevel.Warning);
849849
logging += $"{string.Join(", ", logs.Select(l => l.Message))}\n";
850+
isNavigationSuppressed = (string)((IJavaScriptExecutor)Browser).ExecuteScript("return sessionStorage.getItem('suppress-enhanced-navigation');");
850851

851-
var testId = ((IJavaScriptExecutor)Browser).ExecuteScript("return sessionStorage.getItem('test-id');");
852-
logging += $" testId: {testId}\n";
853-
if (testId is null)
854-
{
855-
continue;
856-
}
857-
var suppressKey = $"suppress-enhanced-navigation-{testId}";
858-
859-
var enhancedNavAttached = ((IJavaScriptExecutor)Browser).ExecuteScript("return sessionStorage.getItem('blazor-enhanced-nav-attached');");
860-
isNavigationSuppressed = (string)((IJavaScriptExecutor)Browser).ExecuteScript($"return sessionStorage.getItem('{suppressKey}');");
861-
862-
logging += $" suppressKey: {suppressKey}\n";
863-
logging += $" {suppressKey}: {isNavigationSuppressed}\n";
852+
logging += $" isNavigationSuppressed: {isNavigationSuppressed}\n";
864853
// Maybe the check was done too early to change the DOM ref, retry
865854
}
866855

src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTestUtil.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@ public static void SuppressEnhancedNavigation<TServerFixture>(ServerTestBase<TSe
3434
throw new InvalidOperationException("Session storage not found. Ensure that the browser is on the correct origin by navigating to a page or by setting skipNavigation to false.", ex);
3535
}
3636

37-
var testId = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('test-id')");
38-
if (testId is null || string.IsNullOrEmpty(testId as string))
39-
{
40-
testId = GenerateTestId(browser);
41-
}
42-
43-
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.setItem('suppress-enhanced-navigation-{testId}', 'true')");
37+
((IJavaScriptExecutor)browser).ExecuteScript("sessionStorage.setItem('suppress-enhanced-navigation', 'true')");
4438

45-
var suppressEnhancedNavigation = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('suppress-enhanced-navigation-{testId}');");
39+
var suppressEnhancedNavigation = ((IJavaScriptExecutor)browser).ExecuteScript("return sessionStorage.getItem('suppress-enhanced-navigation');");
4640
Assert.True(suppressEnhancedNavigation is not null && (string)suppressEnhancedNavigation == "true",
4741
"Expected 'suppress-enhanced-navigation' to be set in sessionStorage.");
4842
_isSuppressed = true;
@@ -75,15 +69,7 @@ public static void CleanEnhancedNavigationSuppression<TServerFixture>(ServerTest
7569
}
7670
NavigateToOrigin(fixture);
7771
}
78-
79-
var testId = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('test-id')");
80-
if (testId is null || string.IsNullOrEmpty(testId as string))
81-
{
82-
return;
83-
}
84-
85-
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.removeItem('test-id')");
86-
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.removeItem('suppress-enhanced-navigation-{testId}')");
72+
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.removeItem('suppress-enhanced-navigation')");
8773
}
8874
catch (WebDriverException ex) when (ex.Message.Contains("invalid session id"))
8975
{
@@ -106,13 +92,6 @@ private static void NavigateToOrigin<TServerFixture>(ServerTestBase<TServerFixtu
10692
fixture.Browser.Exists(By.Id("session-storage-anchor"));
10793
}
10894

109-
private static string GenerateTestId(IWebDriver browser)
110-
{
111-
var testId = Guid.NewGuid().ToString("N")[..8];
112-
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.setItem('test-id', '{testId}')");
113-
return testId;
114-
}
115-
11695
public static long GetScrollY(this IWebDriver browser)
11796
=> Convert.ToInt64(((IJavaScriptExecutor)browser).ExecuteScript("return window.scrollY"), CultureInfo.CurrentCulture);
11897

src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@
137137
}
138138
139139
const enableClassicInitializers = sessionStorage.getItem('enable-classic-initializers') === 'true';
140-
const testId = sessionStorage.getItem('test-id');
141-
const suppressEnhancedNavigation = testId ? sessionStorage.getItem(`suppress-enhanced-navigation-${testId}`) === 'true' : false;
140+
const suppressEnhancedNavigation = sessionStorage.getItem('suppress-enhanced-navigation') === 'true';
142141
const blockLoadBootResource = sessionStorage.getItem('block-load-boot-resource') === 'true';
143142
const blockWebassemblySettings = sessionStorage.getItem('block-webassembly-settings') === 'true';
144143
sessionStorage.removeItem('block-load-boot-resource');

src/Components/test/testassets/Components.TestServer/RazorComponents/Root.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
<script src="@Assets["_framework/blazor.web.js"]" autostart="false"></script>
1616
<script>
17-
const testId = sessionStorage.getItem('test-id');
18-
const suppressEnhancedNavigation = testId ? sessionStorage.getItem(`suppress-enhanced-navigation-${testId}`) === 'true' : false;
17+
const suppressEnhancedNavigation = sessionStorage.getItem('suppress-enhanced-navigation') === 'true';
1918
2019
let pwr = Promise.withResolvers();
2120
let reconnectPromise = pwr.promise;

0 commit comments

Comments
 (0)