diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs index 1b8145c69ae7d..c0e2a2e60cce0 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs @@ -16,7 +16,6 @@ public record BlazorRunOptions bool CheckCounter = true, Dictionary? ServerEnvironment = null, Func? Test = null, - Action? OnPageLoaded = null, Action? OnConsoleMessage = null, Action? OnServerMessage = null, Action? OnErrorMessage = null, diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs index d66fa1d04a0fb..da9c7764f2d1f 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs @@ -202,7 +202,6 @@ public async Task BlazorRunTest(string runArgs, var page = await runner.RunAsync( runCommand, runArgs, - onPageLoaded: runOptions.OnPageLoaded, onConsoleMessage: OnConsoleMessage, onServerMessage: runOptions.OnServerMessage, onError: OnErrorMessage, diff --git a/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs b/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs index 291c2d472ea06..c29233c698441 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs @@ -122,7 +122,6 @@ public async Task RunAsync( string args, bool headless = true, Action? onConsoleMessage = null, - Action? onPageLoaded = null, Action? onServerMessage = null, Action? onError = null, Func? modifyBrowserUrl = null) @@ -130,14 +129,13 @@ public async Task RunAsync( var urlString = await StartServerAndGetUrlAsync(cmd, args, onServerMessage); var browser = await SpawnBrowserAsync(urlString, headless); var context = await browser.NewContextAsync(); - return await RunAsync(context, urlString, headless, onPageLoaded, onConsoleMessage, onError, modifyBrowserUrl); + return await RunAsync(context, urlString, headless, onConsoleMessage, onError, modifyBrowserUrl); } public async Task RunAsync( IBrowserContext context, string browserUrl, bool headless = true, - Action? onPageLoaded = null, Action? onConsoleMessage = null, Action? onError = null, Func? modifyBrowserUrl = null, @@ -150,8 +148,6 @@ public async Task RunAsync( browserUrl = modifyBrowserUrl(browserUrl); IPage page = await context.NewPageAsync(); - if (onPageLoaded is not null) - page.Load += (_, _) => onPageLoaded(page); if (onConsoleMessage is not null) page.Console += (_, msg) => onConsoleMessage(page, msg); diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs index 7647b16586209..01a1afe96c0bb 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs @@ -110,7 +110,6 @@ private async Task RunSdkStyleApp(RunOptions options, BlazorRunHost h CheckCounter: false, Config: options.Configuration, ServerEnvironment: options.ServerEnvironment, - OnPageLoaded: options.OnPageLoaded, OnConsoleMessage: OnConsoleMessage, OnServerMessage: OnServerMessage, BrowserPath: options.BrowserPath, @@ -170,7 +169,6 @@ protected record RunOptions( string? TestScenario = null, Dictionary BrowserQueryString = null, Dictionary ServerEnvironment = null, - Action OnPageLoaded = null, Action OnConsoleMessage = null, Action OnServerMessage = null, int? ExpectedExitCode = 0 diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SignalRClientTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SignalRClientTests.cs index b1e46d5110067..eeda072308991 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SignalRClientTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SignalRClientTests.cs @@ -47,14 +47,28 @@ public async Task SignalRPassMessages(string config, string transport) ServerEnvironment: new Dictionary { ["ASPNETCORE_ENVIRONMENT"] = "Development" }, BrowserPath: "/chat", BrowserQueryString: new Dictionary { ["transport"] = transport, ["message"] = "ping" }, - OnPageLoaded: async page => await page.ClickAsync("button#connectButton"), - OnServerMessage: (msg) => { serverOutput.Add(msg); }, + OnServerMessage: (msg) => serverOutput.Add(msg), OnConsoleMessage: async (page, msg) => { consoleOutput.Add(msg.Text); if (msg.Text.Contains("TestOutput ->")) _testOutput.WriteLine(msg.Text); + // prevent timeouts with [Long Running Test] on error + if (msg.Text.ToLowerInvariant().Contains("error")) + { + Console.WriteLine(msg.Text); + Console.WriteLine(_testOutput); + throw new Exception(msg.Text); + } + + if (msg.Text.Contains("Finished GetQueryParameters")) + { + // first click after render - make sure buttons are available + await page.WaitForSelectorAsync("button#connectButton"); + await page.ClickAsync("button#connectButton"); + } + if (msg.Text.Contains("SignalR connected")) await page.ClickAsync("button#subscribeButton"); diff --git a/src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/Pages/Chat.razor b/src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/Pages/Chat.razor index 22fc7317b7557..f90aa96c87b92 100644 --- a/src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/Pages/Chat.razor +++ b/src/mono/wasm/testassets/BlazorHostedApp/BlazorHosted.Client/Pages/Chat.razor @@ -27,12 +27,23 @@ private List chatMessages = new List(); private string wrongQueryError = "Query string with parameters 'message' and 'transport' are required"; + // remove when https://github.com/dotnet/runtime/issues/96546 is fixed + // log that rendering is about to start in case we hit the issue before OnAfterRender is called + protected override bool ShouldRender() + { + bool shouldRender = base.ShouldRender(); + Helper.TestOutputWriteLine($"ShouldRender = {shouldRender}"); + return shouldRender; + } + protected override void OnAfterRender(bool firstRender) { + if (firstRender) + { + Helper.TestOutputWriteLine($"OnAfterRender on CurrentManagedThreadId={Environment.CurrentManagedThreadId}"); + GetQueryParameters(); + } base.OnAfterRender(firstRender); - - Helper.TestOutputWriteLine($"OnAfterRender on CurrentManagedThreadId={Environment.CurrentManagedThreadId}"); - GetQueryParameters(); } private void GetQueryParameters() @@ -49,7 +60,7 @@ } transport = Helper.GetValue(parameters, "transport"); message = $"{transport} {Helper.GetValue(parameters, "message")}" ; - Helper.TestOutputWriteLine($"GetQueryParameters on CurrentManagedThreadId={Environment.CurrentManagedThreadId} finished"); + Helper.TestOutputWriteLine($"Finished GetQueryParameters on CurrentManagedThreadId={Environment.CurrentManagedThreadId}."); } private async Task Connect()