Skip to content

Commit 3b13040

Browse files
committed
Merge in 'release/8.0' changes
2 parents 3aabc7d + e66069b commit 3b13040

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

src/Components/WebView/test/E2ETest/BasicBlazorHybridTest.cs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ public void Run()
1818
// Note: This test produces *a lot* of debug output to aid when debugging failures. The only output
1919
// that is necessary for the functioning of this test is the "Test passed" at the end of this method.
2020

21-
Console.WriteLine($"Current directory: {Environment.CurrentDirectory}");
22-
Console.WriteLine($"Current assembly: {typeof(Program).Assembly.Location}");
21+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Current directory: {Environment.CurrentDirectory}");
22+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Current assembly: {typeof(Program).Assembly.Location}");
2323
var thisProgramDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
2424

2525
// Add correct runtime sub-folder to PATH to ensure native files are discovered (this is supposed to happen automatically, but somehow it doesn't...)
2626
var newNativePath = Path.Combine(thisProgramDir, "runtimes", RuntimeInformation.RuntimeIdentifier, "native");
27-
Console.WriteLine($"Adding new native path: {newNativePath}");
27+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Adding new native path: {newNativePath}");
2828
Environment.SetEnvironmentVariable("PATH", newNativePath + ";" + Environment.GetEnvironmentVariable("PATH"));
29-
Console.WriteLine($"New PATH env var: {Environment.GetEnvironmentVariable("PATH")}");
29+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] New PATH env var: {Environment.GetEnvironmentVariable("PATH")}");
3030

3131
var thisAppFiles = Directory.GetFiles(thisProgramDir, "*", SearchOption.AllDirectories).ToArray();
32-
Console.WriteLine($"Found {thisAppFiles.Length} files in this app:");
32+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Found {thisAppFiles.Length} files in this app:");
3333
foreach (var file in thisAppFiles)
3434
{
35-
Console.WriteLine($"\t{file}");
35+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] \t{file}");
3636
}
3737

3838
var hostPage = "wwwroot/webviewtesthost.html";
@@ -41,7 +41,7 @@ public void Run()
4141
serviceCollection.AddBlazorWebView();
4242
serviceCollection.AddSingleton<HttpClient>();
4343

44-
Console.WriteLine($"Creating BlazorWindow...");
44+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Creating BlazorWindow...");
4545
BlazorWindow mainWindow = null;
4646
try
4747
{
@@ -53,27 +53,27 @@ public void Run()
5353
}
5454
catch (Exception ex)
5555
{
56-
Console.WriteLine($"Exception {ex.GetType().FullName} while creating window: {ex.Message}");
56+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Exception {ex.GetType().FullName} while creating window: {ex.Message}");
5757
Console.WriteLine(ex.StackTrace);
5858
}
5959

60-
Console.WriteLine($"Hooking exception handler...");
60+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Hooking exception handler...");
6161
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
6262
{
6363
Console.Write(
6464
"Fatal exception" + Environment.NewLine +
6565
error.ExceptionObject.ToString() + Environment.NewLine);
6666
};
6767

68-
Console.WriteLine($"Setting up root components...");
68+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Setting up root components...");
6969
mainWindow.RootComponents.Add<Pages.TestPage>("root");
7070

71-
Console.WriteLine($"Running window...");
71+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Running window...");
7272

7373
const string NewControlDivValueMessage = "wvt:NewControlDivValue";
7474
var isWebViewReady = false;
7575

76-
Console.WriteLine($"RegisterWebMessageReceivedHandler...");
76+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] RegisterWebMessageReceivedHandler...");
7777
mainWindow.PhotinoWindow.RegisterWebMessageReceivedHandler((s, msg) =>
7878
{
7979
if (!msg.StartsWith("__bwv:", StringComparison.Ordinal))
@@ -90,29 +90,33 @@ public void Run()
9090
});
9191
var testPassed = false;
9292

93+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Attaching WindowCreated handler...");
9394
mainWindow.PhotinoWindow.WindowCreated += (s, e) =>
9495
{
96+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] In WindowCreated event...");
9597
Task.Run(async () =>
9698
{
99+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] In async test task...");
100+
97101
try
98102
{
99103
// This is the actual test logic here (wait for WebView, click button, verify updates, etc.)
100104

101105
// 1. Wait for WebView ready
102-
Console.WriteLine($"Waiting for WebView ready...");
106+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Waiting for WebView ready...");
103107
var isWebViewReadyRetriesLeft = 20;
104108
while (!isWebViewReady)
105109
{
106-
Console.WriteLine($"WebView not ready yet, waiting 1sec...");
110+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] WebView not ready yet, waiting 1sec...");
107111
await Task.Delay(1000);
108112
isWebViewReadyRetriesLeft--;
109113
if (isWebViewReadyRetriesLeft == 0)
110114
{
111-
Console.WriteLine($"WebView never became ready, failing the test...");
115+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] WebView never became ready, failing the test...");
112116
return;
113117
}
114118
}
115-
Console.WriteLine($"WebView is ready!");
119+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] WebView is ready!");
116120

117121
// 2. Check TestPage starting state
118122
if (!await WaitForControlDiv(mainWindow.PhotinoWindow, controlValueToWaitFor: "0"))
@@ -130,7 +134,7 @@ public void Run()
130134
}
131135

132136
// 5. If we get here, it all worked!
133-
Console.WriteLine($"All tests passed!");
137+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] All tests passed!");
134138
testPassed = true;
135139
}
136140
catch (Exception ex)
@@ -153,16 +157,16 @@ public void Run()
153157
}
154158
catch (Exception ex)
155159
{
156-
Console.WriteLine($"Exception while running window: {ex}");
160+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Exception while running window: {ex}");
157161
}
158162

159163
// This line is what's required for the test to be considered as passed. The xUnit test in WebViewManagerE2ETests checks
160164
// that this reports success and that decides if the test is pass/fail.
161-
Console.WriteLine($"Test passed? {testPassed}");
165+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Test passed? {testPassed}");
162166
}
163167

164168
const int MaxWaitTimes = 30;
165-
const int WaitTimeInMS = 250;
169+
const int WaitTimeInMS = 1000;
166170

167171
public async Task<bool> WaitForControlDiv(PhotinoWindow photinoWindow, string controlValueToWaitFor)
168172
{
@@ -172,20 +176,20 @@ public async Task<bool> WaitForControlDiv(PhotinoWindow photinoWindow, string co
172176
// Tell WebView to report the current controlDiv value (this is inside the loop because
173177
// it's possible for this to execute before the WebView has finished processing previous
174178
// C#-generated events, such as WebView button clicks).
175-
Console.WriteLine($"Asking WebView for current controlDiv value...");
179+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Asking WebView for current controlDiv value...");
176180
photinoWindow.SendWebMessage($"wvt:GetControlDivValue");
177181

178182
// And wait for the value to appear
179183
if (_latestControlDivValue == controlValueToWaitFor)
180184
{
181-
Console.WriteLine($"WebView reported the expected controlDiv value of {controlValueToWaitFor}!");
185+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] WebView reported the expected controlDiv value of {controlValueToWaitFor}!");
182186
return true;
183187
}
184-
Console.WriteLine($"Waiting for controlDiv to have value '{controlValueToWaitFor}', but it's still '{_latestControlDivValue}', so waiting {WaitTimeInMS}ms.");
188+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Waiting for controlDiv to have value '{controlValueToWaitFor}', but it's still '{_latestControlDivValue}', so waiting {WaitTimeInMS}ms.");
185189
await Task.Delay(WaitTimeInMS);
186190
}
187191

188-
Console.WriteLine($"Waited {MaxWaitTimes * WaitTimeInMS}ms but couldn't get controlDiv to have value '{controlValueToWaitFor}' (last value is '{_latestControlDivValue}').");
192+
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] Waited {MaxWaitTimes * WaitTimeInMS}ms but couldn't get controlDiv to have value '{controlValueToWaitFor}' (last value is '{_latestControlDivValue}').");
189193
return false;
190194
}
191195
}

src/Components/WebView/test/E2ETest/WebViewManagerE2ETests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
using System.Diagnostics;
55
using Microsoft.AspNetCore.Testing;
6+
using Xunit.Abstractions;
67

78
namespace Microsoft.AspNetCore.Components.WebViewE2E.Test;
89

9-
public class WebViewManagerE2ETests
10+
public class WebViewManagerE2ETests(ITestOutputHelper output)
1011
{
1112
// Skips:
1213
// - Ubuntu is skipped due to this error:
@@ -39,7 +40,9 @@ public async Task CanLaunchPhotinoWebViewAndClickButton()
3940

4041
var testProgramOutput = photinoProcess.StandardOutput.ReadToEnd();
4142

42-
await photinoProcess.WaitForExitAsync().TimeoutAfter(TimeSpan.FromSeconds(30));
43+
await photinoProcess.WaitForExitAsync().TimeoutAfter(TimeSpan.FromSeconds(60));
44+
45+
output.WriteLine(testProgramOutput);
4346

4447
// The test app reports its own results by calling Console.WriteLine(), so here we only need to verify that
4548
// the test internally believes it passed (and we trust it!).

0 commit comments

Comments
 (0)