Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override async Task InitializeAsync()
// instance across tests (One of the tests closes the browser). For that reason we simply create
// a new browser instance for every test in this class sos that there are no issues when running
// them together.
await base.InitializeAsync(Guid.NewGuid().ToString());
await base.InitializeAsync(null);
}

protected override void InitializeAsyncCore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public HotReloadTest(

public override async Task InitializeAsync()
{
await base.InitializeAsync(Guid.NewGuid().ToString());
await base.InitializeAsync(null);
}

protected override void InitializeAsyncCore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override async Task InitializeAsync()
{
// Since browser storage needs to be reset in between tests, it's easiest for each
// test to run in its own browser instance.
await base.InitializeAsync(Guid.NewGuid().ToString());
await base.InitializeAsync(null);
}

protected override void InitializeAsyncCore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override void InitializeAsyncCore()
_appElement = Browser.MountTestComponent<BinaryHttpRequestsComponent>();
}

public override Task InitializeAsync() => base.InitializeAsync(Guid.NewGuid().ToString());
public override Task InitializeAsync() => base.InitializeAsync(null);

[Fact]
public void CanSendAndReceiveBytes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BootResourceCachingTest(

public override Task InitializeAsync()
{
return base.InitializeAsync(Guid.NewGuid().ToString());
return base.InitializeAsync(null);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Components/test/E2ETest/Tests/PerformanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override void InitializeAsyncCore()
Navigate("/");
}

public override Task InitializeAsync() => base.InitializeAsync(Guid.NewGuid().ToString());
public override Task InitializeAsync() => base.InitializeAsync(null);

[Fact]
public void HasTitle()
Expand Down
2 changes: 1 addition & 1 deletion src/Components/test/E2ETest/Tests/SignalRClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void InitializeAsyncCore()
Browser.Exists(By.Id("signalr-client"));
}

public override Task InitializeAsync() => base.InitializeAsync(Guid.NewGuid().ToString());
public override Task InitializeAsync() => base.InitializeAsync(null);

[Fact]
public void SignalRClientWorksWithLongPolling()
Expand Down
24 changes: 15 additions & 9 deletions src/Shared/E2ETesting/BrowserFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void EnforceSupportedConfigurations()

public static bool IsHostAutomationSupported()
{
// We emit an assemblymetadata attribute that reflects the value of SeleniumE2ETestsSupported at build
// We emit an AssemblyMetadata attribute that reflects the value of SeleniumE2ETestsSupported at build
// time and we use that to conditionally skip Selenium tests parts.
var attribute = typeof(BrowserFixture).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.SingleOrDefault(a => a.Key == "Microsoft.AspNetCore.InternalTesting.Selenium.Supported");
Expand All @@ -66,20 +66,21 @@ public static bool IsHostAutomationSupported()

public async Task DisposeAsync()
{
try
var browsers = _browsers.Values;
foreach (var (browser, _) in browsers)
{
var browsers = _browsers.Values;
foreach (var (browser, _) in browsers)
try
{
browser?.Quit();
browser?.Dispose();
}

await DeleteBrowserUserProfileDirectoriesAsync();
}
catch
{
catch
{
// Continue disposing other browsers
}
}

await DeleteBrowserUserProfileDirectoriesAsync();
}

private async Task DeleteBrowserUserProfileDirectoriesAsync()
Expand Down Expand Up @@ -123,6 +124,11 @@ private async Task DeleteBrowserUserProfileDirectoriesAsync()
return default;
}

if (isolationContext == null)
{
return CreateBrowser(null, output);
}

return _browsers.GetOrAdd(isolationContext, CreateBrowser, output);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Shared/E2ETesting/BrowserTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BrowserTestBase : IClassFixture<BrowserFixture>, IAsyncLifetime

private ExceptionDispatchInfo _exceptionDispatchInfo;
private IWebDriver _browser;
protected string _isolationContext;

public BrowserTestBase(BrowserFixture browserFixture, ITestOutputHelper output)
{
Expand Down Expand Up @@ -51,6 +52,11 @@ public IWebDriver Browser

public Task DisposeAsync()
{
if (_isolationContext == null)
{
Browser.Dispose();
}

return Task.CompletedTask;
}

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

public virtual Task InitializeAsync(string isolationContext)
{
// If isolationContext is null then the Browser is not cached

InitializeBrowser(isolationContext);
InitializeAsyncCore();
return Task.CompletedTask;
Expand All @@ -74,11 +82,14 @@ protected void InitializeBrowser(string isolationContext)
{
try
{
Browser?.Dispose();

var (browser, logs) = BrowserFixture.GetOrCreateBrowser(Output, isolationContext);
_asyncBrowser.Value = browser;
_logs.Value = logs;

Browser = browser;
_isolationContext = isolationContext;
}
catch (Exception ex)
{
Expand Down
Loading