Skip to content

Commit 8b62ae8

Browse files
committed
Revert "Grant ID for each test on initialization. Change BinaryHttpClientTest inheritance to ServerTestBase, so that it calls ID granting method as well."
This reverts commit 7ac455c.
1 parent 88135be commit 8b62ae8

File tree

4 files changed

+13
-40
lines changed

4 files changed

+13
-40
lines changed

src/Components/test/E2ETest/Infrastructure/ServerTestBase.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,4 @@ protected override void InitializeAsyncCore()
4444
// Make sure each test starts clean.
4545
((IJavaScriptExecutor)Browser).ExecuteScript("console.clear()");
4646
}
47-
48-
protected override void GrantTestId()
49-
{
50-
EnhancedNavigationTestUtil.GrantTestId(this);
51-
}
5247
}

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ public static void SuppressEnhancedNavigation<TServerFixture>(ServerTestBase<TSe
2222
{
2323
NavigateToOrigin(fixture);
2424
}
25-
AssertSessionStorageAvailable(browser);
25+
26+
try
27+
{
28+
((IJavaScriptExecutor)browser).ExecuteScript("sessionStorage.length");
29+
}
30+
catch (Exception ex)
31+
{
32+
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);
33+
}
2634

2735
var testId = ((IJavaScriptExecutor)browser).ExecuteScript($"return sessionStorage.getItem('test-id')");
2836
if (testId is null || string.IsNullOrEmpty(testId as string))
2937
{
30-
throw new InvalidOperationException("Test ID not found in sessionStorage. Make sure your test class grants it in InitializeAsync.");
38+
testId = GrantTestId(browser);
3139
}
3240

3341
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.setItem('suppress-enhanced-navigation-{testId}', 'true')");
@@ -38,27 +46,6 @@ public static void SuppressEnhancedNavigation<TServerFixture>(ServerTestBase<TSe
3846
}
3947
}
4048

41-
public static void AssertSessionStorageAvailable(IWebDriver browser)
42-
{
43-
try
44-
{
45-
((IJavaScriptExecutor)browser).ExecuteScript("sessionStorage.length");
46-
}
47-
catch (Exception ex)
48-
{
49-
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);
50-
}
51-
52-
}
53-
54-
public static void GrantTestId<TServerFixture>(ServerTestBase<TServerFixture> fixture)
55-
where TServerFixture : ServerFixture
56-
{
57-
NavigateToOrigin(fixture);
58-
AssertSessionStorageAvailable(fixture.Browser);
59-
GrantTestIdCore(fixture.Browser);
60-
}
61-
6249
public static void CleanEnhancedNavigationSuppression<TServerFixture>(ServerTestBase<TServerFixture> fixture, bool skipNavigation = false)
6350
where TServerFixture : ServerFixture
6451
{
@@ -107,7 +94,7 @@ private static void NavigateToOrigin<TServerFixture>(ServerTestBase<TServerFixtu
10794
fixture.Browser.Equal("Hello", () => fixture.Browser.Exists(By.TagName("h1")).Text);
10895
}
10996

110-
private static string GrantTestIdCore(IWebDriver browser)
97+
private static string GrantTestId(IWebDriver browser)
11198
{
11299
var testId = Guid.NewGuid().ToString("N")[..8];
113100
((IJavaScriptExecutor)browser).ExecuteScript($"sessionStorage.setItem('test-id', '{testId}')");

src/Components/test/E2ETest/Tests/BinaryHttpClientTest.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using BasicTestApp.HttpClientTest;
5-
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
65
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
7-
using Microsoft.AspNetCore.Components.E2ETests.ServerRenderingTests;
86
using Microsoft.AspNetCore.E2ETesting;
97
using OpenQA.Selenium;
108
using TestServer;
119
using Xunit.Abstractions;
1210

1311
namespace Microsoft.AspNetCore.Components.E2ETest.Tests;
1412

15-
public class BinaryHttpClientTest : ServerTestBase<AspNetSiteServerFixture>,
13+
public class BinaryHttpClientTest : BrowserTestBase,
1614
IClassFixture<BasicTestAppServerSiteFixture<CorsStartup>>,
1715
IClassFixture<BlazorWasmTestAppFixture<BasicTestApp.Program>>
1816
{
@@ -25,13 +23,11 @@ public class BinaryHttpClientTest : ServerTestBase<AspNetSiteServerFixture>,
2523

2624
public BinaryHttpClientTest(
2725
BrowserFixture browserFixture,
28-
AspNetSiteServerFixture serverFixture,
2926
BlazorWasmTestAppFixture<BasicTestApp.Program> devHostServerFixture,
3027
BasicTestAppServerSiteFixture<CorsStartup> apiServerFixture,
3128
ITestOutputHelper output)
32-
: base(browserFixture, serverFixture, output)
29+
: base(browserFixture, output)
3330
{
34-
serverFixture.BuildWebHostMethod = Program.BuildWebHost<CorsStartup>;
3531
_devHostServerFixture = devHostServerFixture;
3632
_devHostServerFixture.PathBase = "/subdir";
3733
_apiServerFixture = apiServerFixture;

src/Shared/E2ETesting/BrowserTestBase.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public virtual Task InitializeAsync()
6262
public virtual Task InitializeAsync(string isolationContext)
6363
{
6464
InitializeBrowser(isolationContext);
65-
GrantTestId();
6665
InitializeAsyncCore();
6766
return Task.CompletedTask;
6867
}
@@ -71,10 +70,6 @@ protected virtual void InitializeAsyncCore()
7170
{
7271
}
7372

74-
protected virtual void GrantTestId()
75-
{
76-
}
77-
7873
protected void InitializeBrowser(string isolationContext)
7974
{
8075
try

0 commit comments

Comments
 (0)