Skip to content

Commit 4b1f572

Browse files
committed
Each test should have a testId.
1 parent 66d2b0b commit 4b1f572

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ public EnhancedNavigationTest(
3131
// One of the tests here makes use of the streaming rendering page, which uses global state
3232
// so we can't run at the same time as other such tests
3333
public override Task InitializeAsync()
34-
=> InitializeAsync(BrowserFixture.StreamingContext);
34+
{
35+
var initTask = InitializeAsync(BrowserFixture.StreamingContext);
36+
var testId = Guid.NewGuid().ToString("N")[..8];
37+
((IJavaScriptExecutor)Browser).ExecuteScript($"sessionStorage.setItem('test-id', '{testId}')");
38+
return initTask;
39+
}
3540

3641
[Fact]
3742
public void CanNavigateToAnotherPageWhilePreservingCommonDOMElements()
@@ -731,10 +736,10 @@ public void EnhancedNavigationScrollBehavesSameAsBrowserOnNavigation(bool enable
731736
}
732737

733738
[Theory]
734-
[InlineData(false, false, false)] // https://github.com/dotnet/aspnetcore/issues/60875
739+
[InlineData(false, false, false)]
735740
[InlineData(false, true, false)]
736741
[InlineData(true, true, false)]
737-
[InlineData(true, false, false)] // https://github.com/dotnet/aspnetcore/issues/60875
742+
[InlineData(true, false, false)]
738743
// [InlineData(false, false, true)] programmatic navigation doesn't work without enhanced navigation
739744
[InlineData(false, true, true)]
740745
[InlineData(true, true, true)]

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ public static void SuppressEnhancedNavigation<TServerFixture>(ServerTestBase<TSe
2929

3030
// Set the suppression flag - this will prevent enhanced navigation from being attached on the next navigation
3131
// and trigger detachment of currently attached enhanced navigation via the periodic check
32-
var testId = Guid.NewGuid().ToString("N")[..8];
33-
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.setItem('test-id', '{testId}')");
32+
var testId = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('test-id')");
33+
if (testId == null)
34+
{
35+
throw new InvalidOperationException("Test ID not found in sessionStorage. Ensure that the test ID is set in InitializeAsync before calling this method.");
36+
}
3437
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.setItem('suppress-enhanced-navigation-{testId}', 'true')");
3538

3639
var suppressEnhancedNavigation = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('suppress-enhanced-navigation-{testId}');");

0 commit comments

Comments
 (0)