Skip to content

Commit 503f7e9

Browse files
committed
Improve E2E tests performance
1 parent b7738d2 commit 503f7e9

File tree

9 files changed

+34
-10
lines changed

9 files changed

+34
-10
lines changed

src/Components/test/E2ETest/ServerExecutionTests/CircuitGracefulTerminationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override async Task InitializeAsync()
3333
// instance across tests (One of the tests closes the browser). For that reason we simply create
3434
// a new browser instance for every test in this class sos that there are no issues when running
3535
// them together.
36-
await base.InitializeAsync(Guid.NewGuid().ToString());
36+
await base.InitializeAsync(null);
3737
}
3838

3939
protected override void InitializeAsyncCore()

src/Components/test/E2ETest/ServerExecutionTests/HotReloadTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public HotReloadTest(
2424

2525
public override async Task InitializeAsync()
2626
{
27-
await base.InitializeAsync(Guid.NewGuid().ToString());
27+
await base.InitializeAsync(null);
2828
}
2929

3030
protected override void InitializeAsyncCore()

src/Components/test/E2ETest/ServerExecutionTests/ProtectedBrowserStorageUsageTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override async Task InitializeAsync()
2626
{
2727
// Since browser storage needs to be reset in between tests, it's easiest for each
2828
// test to run in its own browser instance.
29-
await base.InitializeAsync(Guid.NewGuid().ToString());
29+
await base.InitializeAsync(null);
3030
}
3131

3232
protected override void InitializeAsyncCore()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override void InitializeAsyncCore()
3939
_appElement = Browser.MountTestComponent<BinaryHttpRequestsComponent>();
4040
}
4141

42-
public override Task InitializeAsync() => base.InitializeAsync(Guid.NewGuid().ToString());
42+
public override Task InitializeAsync() => base.InitializeAsync(null);
4343

4444
[Fact]
4545
public void CanSendAndReceiveBytes()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public BootResourceCachingTest(
3232

3333
public override Task InitializeAsync()
3434
{
35-
return base.InitializeAsync(Guid.NewGuid().ToString());
35+
return base.InitializeAsync(null);
3636
}
3737

3838
[Fact]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected override void InitializeAsyncCore()
2525
Navigate("/");
2626
}
2727

28-
public override Task InitializeAsync() => base.InitializeAsync(Guid.NewGuid().ToString());
28+
public override Task InitializeAsync() => base.InitializeAsync(null);
2929

3030
[Fact]
3131
public void HasTitle()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected override void InitializeAsyncCore()
3535
Browser.Exists(By.Id("signalr-client"));
3636
}
3737

38-
public override Task InitializeAsync() => base.InitializeAsync(Guid.NewGuid().ToString());
38+
public override Task InitializeAsync() => base.InitializeAsync(null);
3939

4040
[Fact]
4141
public void SignalRClientWorksWithLongPolling()

src/Shared/E2ETesting/BrowserFixture.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.AspNetCore.E2ETesting;
1414
public class BrowserFixture : IAsyncLifetime
1515
{
1616
public static string StreamingContext { get; } = "streaming";
17+
1718
private readonly ConcurrentDictionary<string, (IWebDriver browser, ILogs log)> _browsers = new();
1819

1920
public BrowserFixture(IMessageSink diagnosticsMessageSink)
@@ -39,7 +40,7 @@ public static void EnforceSupportedConfigurations()
3940

4041
public static bool IsHostAutomationSupported()
4142
{
42-
// We emit an assemblymetadata attribute that reflects the value of SeleniumE2ETestsSupported at build
43+
// We emit an AssemblyMetadata attribute that reflects the value of SeleniumE2ETestsSupported at build
4344
// time and we use that to conditionally skip Selenium tests parts.
4445
var attribute = typeof(BrowserFixture).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
4546
.SingleOrDefault(a => a.Key == "Microsoft.AspNetCore.InternalTesting.Selenium.Supported");
@@ -66,8 +67,15 @@ public async Task DisposeAsync()
6667
var browsers = _browsers.Values;
6768
foreach (var (browser, _) in browsers)
6869
{
69-
browser?.Quit();
70-
browser?.Dispose();
70+
try
71+
{
72+
browser?.Quit();
73+
browser?.Dispose();
74+
}
75+
catch
76+
{
77+
// Continue disposing other browsers
78+
}
7179
}
7280

7381
await DeleteBrowserUserProfileDirectoriesAsync();
@@ -114,6 +122,11 @@ private async Task DeleteBrowserUserProfileDirectoriesAsync()
114122
return default;
115123
}
116124

125+
if (isolationContext == null)
126+
{
127+
return CreateBrowser(null, output);
128+
}
129+
117130
return _browsers.GetOrAdd(isolationContext, CreateBrowser, output);
118131
}
119132

src/Shared/E2ETesting/BrowserTestBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class BrowserTestBase : IClassFixture<BrowserFixture>, IAsyncLifetime
1616

1717
private ExceptionDispatchInfo _exceptionDispatchInfo;
1818
private IWebDriver _browser;
19+
protected string _isolationContext;
1920

2021
public BrowserTestBase(BrowserFixture browserFixture, ITestOutputHelper output)
2122
{
@@ -51,6 +52,11 @@ public IWebDriver Browser
5152

5253
public Task DisposeAsync()
5354
{
55+
if (_isolationContext == null)
56+
{
57+
Browser.Dispose();
58+
}
59+
5460
return Task.CompletedTask;
5561
}
5662

@@ -61,6 +67,8 @@ public virtual Task InitializeAsync()
6167

6268
public virtual Task InitializeAsync(string isolationContext)
6369
{
70+
// If isolationContext is null then the Browser is not cached
71+
6472
InitializeBrowser(isolationContext);
6573
InitializeAsyncCore();
6674
return Task.CompletedTask;
@@ -74,11 +82,14 @@ protected void InitializeBrowser(string isolationContext)
7482
{
7583
try
7684
{
85+
Browser?.Dispose();
86+
7787
var (browser, logs) = BrowserFixture.GetOrCreateBrowser(Output, isolationContext);
7888
_asyncBrowser.Value = browser;
7989
_logs.Value = logs;
8090

8191
Browser = browser;
92+
_isolationContext = isolationContext;
8293
}
8394
catch (Exception ex)
8495
{

0 commit comments

Comments
 (0)