diff --git a/src/Components/test/E2ETest/ServerExecutionTests/NavigationLockPrerenderingTest.cs b/src/Components/test/E2ETest/ServerExecutionTests/NavigationLockPrerenderingTest.cs index 6c310a87c253..645a29cc7bfa 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/NavigationLockPrerenderingTest.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/NavigationLockPrerenderingTest.cs @@ -21,6 +21,9 @@ public NavigationLockPrerenderingTest( { } + public override Task InitializeAsync() + => InitializeAsync(BrowserFixture.RoutingTestContext); + [Fact] [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/57153")] public void NavigationIsLockedAfterPrerendering() diff --git a/src/Components/test/E2ETest/Tests/RoutingTest.cs b/src/Components/test/E2ETest/Tests/RoutingTest.cs index cb974cd0151b..3b9ad5e8bf84 100644 --- a/src/Components/test/E2ETest/Tests/RoutingTest.cs +++ b/src/Components/test/E2ETest/Tests/RoutingTest.cs @@ -26,6 +26,9 @@ public RoutingTest( { } + public override Task InitializeAsync() + => InitializeAsync(BrowserFixture.RoutingTestContext); + protected override void InitializeAsyncCore() { Navigate(ServerPathBase); diff --git a/src/Shared/E2ETesting/BrowserFixture.cs b/src/Shared/E2ETesting/BrowserFixture.cs index a2dc7bc692fa..5f13637ed9b6 100644 --- a/src/Shared/E2ETesting/BrowserFixture.cs +++ b/src/Shared/E2ETesting/BrowserFixture.cs @@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.E2ETesting; public class BrowserFixture : IAsyncLifetime { public static string StreamingContext { get; } = "streaming"; + public static string RoutingTestContext { get; } = "routing"; + private readonly ConcurrentDictionary _browsers = new(); public BrowserFixture(IMessageSink diagnosticsMessageSink) @@ -123,6 +125,17 @@ private async Task DeleteBrowserUserProfileDirectoriesAsync() { var opts = new ChromeOptions(); + if (context?.StartsWith(RoutingTestContext, StringComparison.Ordinal) == true) + { + // Enables WebDriver BiDi, which is required to allow the 'beforeunload' event + // to display an alert dialog. This is needed by some of our routing tests. + // See: https://w3c.github.io/webdriver/#user-prompts + // We could consider making this the default for all tests when the BiDi spec + // becomes standard (it's in draft at the time of writing). + // See: https://w3c.github.io/webdriver-bidi/ + opts.UseWebSocketUrl = true; + } + if (context?.StartsWith(StreamingContext, StringComparison.Ordinal) == true) { // Tells Selenium not to wait until the page navigation has completed before continuing with the tests