@@ -18,21 +18,21 @@ public void Run()
18
18
// Note: This test produces *a lot* of debug output to aid when debugging failures. The only output
19
19
// that is necessary for the functioning of this test is the "Test passed" at the end of this method.
20
20
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 } ") ;
23
23
var thisProgramDir = Path . GetDirectoryName ( typeof ( Program ) . Assembly . Location ) ;
24
24
25
25
// Add correct runtime sub-folder to PATH to ensure native files are discovered (this is supposed to happen automatically, but somehow it doesn't...)
26
26
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 } ") ;
28
28
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" ) } ") ;
30
30
31
31
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:") ;
33
33
foreach ( var file in thisAppFiles )
34
34
{
35
- Console . WriteLine ( $ "\t { file } ") ;
35
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] \t { file } ") ;
36
36
}
37
37
38
38
var hostPage = "wwwroot/webviewtesthost.html" ;
@@ -41,7 +41,7 @@ public void Run()
41
41
serviceCollection . AddBlazorWebView ( ) ;
42
42
serviceCollection . AddSingleton < HttpClient > ( ) ;
43
43
44
- Console . WriteLine ( $ "Creating BlazorWindow...") ;
44
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] Creating BlazorWindow...") ;
45
45
BlazorWindow mainWindow = null ;
46
46
try
47
47
{
@@ -53,27 +53,27 @@ public void Run()
53
53
}
54
54
catch ( Exception ex )
55
55
{
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 } ") ;
57
57
Console . WriteLine ( ex . StackTrace ) ;
58
58
}
59
59
60
- Console . WriteLine ( $ "Hooking exception handler...") ;
60
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] Hooking exception handler...") ;
61
61
AppDomain . CurrentDomain . UnhandledException += ( sender , error ) =>
62
62
{
63
63
Console . Write (
64
64
"Fatal exception" + Environment . NewLine +
65
65
error . ExceptionObject . ToString ( ) + Environment . NewLine ) ;
66
66
} ;
67
67
68
- Console . WriteLine ( $ "Setting up root components...") ;
68
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] Setting up root components...") ;
69
69
mainWindow . RootComponents . Add < Pages . TestPage > ( "root" ) ;
70
70
71
- Console . WriteLine ( $ "Running window...") ;
71
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] Running window...") ;
72
72
73
73
const string NewControlDivValueMessage = "wvt:NewControlDivValue" ;
74
74
var isWebViewReady = false ;
75
75
76
- Console . WriteLine ( $ "RegisterWebMessageReceivedHandler...") ;
76
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] RegisterWebMessageReceivedHandler...") ;
77
77
mainWindow . PhotinoWindow . RegisterWebMessageReceivedHandler ( ( s , msg ) =>
78
78
{
79
79
if ( ! msg . StartsWith ( "__bwv:" , StringComparison . Ordinal ) )
@@ -90,29 +90,33 @@ public void Run()
90
90
} ) ;
91
91
var testPassed = false ;
92
92
93
+ Console . WriteLine ( $ "[{ DateTime . Now . ToLongTimeString ( ) } ] Attaching WindowCreated handler...") ;
93
94
mainWindow . PhotinoWindow . WindowCreated += ( s , e ) =>
94
95
{
96
+ Console . WriteLine ( $ "[{ DateTime . Now . ToLongTimeString ( ) } ] In WindowCreated event...") ;
95
97
Task . Run ( async ( ) =>
96
98
{
99
+ Console . WriteLine ( $ "[{ DateTime . Now . ToLongTimeString ( ) } ] In async test task...") ;
100
+
97
101
try
98
102
{
99
103
// This is the actual test logic here (wait for WebView, click button, verify updates, etc.)
100
104
101
105
// 1. Wait for WebView ready
102
- Console . WriteLine ( $ "Waiting for WebView ready...") ;
106
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] Waiting for WebView ready...") ;
103
107
var isWebViewReadyRetriesLeft = 20 ;
104
108
while ( ! isWebViewReady )
105
109
{
106
- Console . WriteLine ( $ "WebView not ready yet, waiting 1sec...") ;
110
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] WebView not ready yet, waiting 1sec...") ;
107
111
await Task . Delay ( 1000 ) ;
108
112
isWebViewReadyRetriesLeft -- ;
109
113
if ( isWebViewReadyRetriesLeft == 0 )
110
114
{
111
- Console . WriteLine ( $ "WebView never became ready, failing the test...") ;
115
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] WebView never became ready, failing the test...") ;
112
116
return ;
113
117
}
114
118
}
115
- Console . WriteLine ( $ "WebView is ready!") ;
119
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] WebView is ready!") ;
116
120
117
121
// 2. Check TestPage starting state
118
122
if ( ! await WaitForControlDiv ( mainWindow . PhotinoWindow , controlValueToWaitFor : "0" ) )
@@ -130,7 +134,7 @@ public void Run()
130
134
}
131
135
132
136
// 5. If we get here, it all worked!
133
- Console . WriteLine ( $ "All tests passed!") ;
137
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] All tests passed!") ;
134
138
testPassed = true ;
135
139
}
136
140
catch ( Exception ex )
@@ -153,16 +157,16 @@ public void Run()
153
157
}
154
158
catch ( Exception ex )
155
159
{
156
- Console . WriteLine ( $ "Exception while running window: { ex } ") ;
160
+ Console . WriteLine ( $ "[ { DateTime . Now . ToLongTimeString ( ) } ] Exception while running window: { ex } ") ;
157
161
}
158
162
159
163
// This line is what's required for the test to be considered as passed. The xUnit test in WebViewManagerE2ETests checks
160
164
// 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 } ") ;
162
166
}
163
167
164
168
const int MaxWaitTimes = 30 ;
165
- const int WaitTimeInMS = 250 ;
169
+ const int WaitTimeInMS = 1000 ;
166
170
167
171
public async Task < bool > WaitForControlDiv ( PhotinoWindow photinoWindow , string controlValueToWaitFor )
168
172
{
@@ -172,20 +176,20 @@ public async Task<bool> WaitForControlDiv(PhotinoWindow photinoWindow, string co
172
176
// Tell WebView to report the current controlDiv value (this is inside the loop because
173
177
// it's possible for this to execute before the WebView has finished processing previous
174
178
// 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...") ;
176
180
photinoWindow . SendWebMessage ( $ "wvt:GetControlDivValue") ;
177
181
178
182
// And wait for the value to appear
179
183
if ( _latestControlDivValue == controlValueToWaitFor )
180
184
{
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 } !") ;
182
186
return true ;
183
187
}
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.") ;
185
189
await Task . Delay ( WaitTimeInMS ) ;
186
190
}
187
191
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 } ').") ;
189
193
return false ;
190
194
}
191
195
}
0 commit comments