-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Run entire E2E test with consistent enhanced navigation suppression setting #63132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
66d2b0b
4b1f572
945c9dd
e9bf1bf
f9601f1
2cd3a18
5fd1050
7c0bf05
b2e8441
08c99cf
73abbda
5ef86a1
357192c
92cad9a
8c5c3b1
189db63
fa057a8
ee4aa34
795b665
a6856fc
249f03a
763ea9d
5696430
e1b6931
1a8d9bf
1339daa
21051c2
0bd2afc
7ac455c
18ee068
6dcfd16
413dd78
88135be
8b62ae8
19793d7
37b0a3c
0f28172
ba57845
860752c
047bd95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@page "/" | ||
|
||
<h1>Hello, world!</h1> | ||
<h1 id="session-storage-anchor">Hello, world!</h1> | ||
|
||
Welcome to your new app. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ namespace Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests; | |
|
||
public static class EnhancedNavigationTestUtil | ||
{ | ||
private static bool _isSuppressed; | ||
|
||
public static void SuppressEnhancedNavigation<TServerFixture>(ServerTestBase<TServerFixture> fixture, bool shouldSuppress, bool skipNavigation = false) | ||
where TServerFixture : ServerFixture | ||
{ | ||
|
@@ -20,16 +22,76 @@ public static void SuppressEnhancedNavigation<TServerFixture>(ServerTestBase<TSe | |
|
||
if (!skipNavigation) | ||
{ | ||
// Normally we need to navigate here first otherwise the browser isn't on the correct origin to access | ||
// localStorage. But some tests are already in the right place and need to avoid extra navigation. | ||
fixture.Navigate($"{fixture.ServerPathBase}/"); | ||
browser.Equal("Hello", () => browser.Exists(By.TagName("h1")).Text); | ||
NavigateToOrigin(fixture); | ||
} | ||
|
||
try | ||
{ | ||
((IJavaScriptExecutor)browser).ExecuteScript("sessionStorage.length"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
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); | ||
} | ||
|
||
((IJavaScriptExecutor)browser).ExecuteScript("sessionStorage.setItem('suppress-enhanced-navigation', 'true')"); | ||
|
||
var suppressEnhancedNavigation = ((IJavaScriptExecutor)browser).ExecuteScript("return sessionStorage.getItem('suppress-enhanced-navigation');"); | ||
Assert.True(suppressEnhancedNavigation is not null && (string)suppressEnhancedNavigation == "true", | ||
"Expected 'suppress-enhanced-navigation' to be set in sessionStorage."); | ||
_isSuppressed = true; | ||
} | ||
} | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static void CleanEnhancedNavigationSuppression<TServerFixture>(ServerTestBase<TServerFixture> fixture, bool skipNavigation = false) | ||
where TServerFixture : ServerFixture | ||
{ | ||
if (!_isSuppressed) | ||
{ | ||
return; | ||
} | ||
|
||
var browser = fixture.Browser; | ||
|
||
try | ||
{ | ||
// First, ensure we're on the correct origin to access sessionStorage | ||
try | ||
{ | ||
// Check if we can access sessionStorage from current location | ||
((IJavaScriptExecutor)browser).ExecuteScript("sessionStorage.length"); | ||
} | ||
catch | ||
{ | ||
if (skipNavigation) | ||
{ | ||
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."); | ||
} | ||
NavigateToOrigin(fixture); | ||
} | ||
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.removeItem('suppress-enhanced-navigation')"); | ||
} | ||
catch (WebDriverException ex) when (ex.Message.Contains("invalid session id")) | ||
{ | ||
// Browser session is no longer valid (e.g., browser was closed) | ||
// Session storage is automatically cleared when browser closes, so cleanup is already done | ||
// This is expected in some tests, so we silently return | ||
return; | ||
} | ||
finally | ||
{ | ||
_isSuppressed = false; | ||
} | ||
} | ||
Comment on lines
+74
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than doing this. Can we check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can try. This was added because we have failures in tests that close the browser intentionally, it should be easy to check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
private static void NavigateToOrigin<TServerFixture>(ServerTestBase<TServerFixture> fixture) | ||
where TServerFixture : ServerFixture | ||
{ | ||
// Navigate to the test origin to ensure the browser is on the correct state to access sessionStorage | ||
fixture.Navigate($"{fixture.ServerPathBase}/"); | ||
fixture.Browser.Exists(By.Id("session-storage-anchor")); | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public static long GetScrollY(this IWebDriver browser) | ||
=> Convert.ToInt64(((IJavaScriptExecutor)browser).ExecuteScript("return window.scrollY"), CultureInfo.CurrentCulture); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@inject NavigationManager navigationManager | ||
|
||
<h1>Graceful Termination</h1> | ||
<h1 id="graceful-termination-title">Graceful Termination</h1> | ||
|
||
<a href="mailto:[email protected]" id="mailto-link">Send Email</a> | ||
<a href="download" download id="download-href">Download Link</a> | ||
|
Uh oh!
There was an error while loading. Please reload this page.