New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix BlazorWebView tests on Windows #16487
Conversation
It seems that the test sometimes waits for an event that already happened, so it doesn't see it happen, and fails. I added a check to evaluate the state of the test to see if it doesn't need to wait for the event and allows the test to continue. Fixes #16187
@@ -27,6 +27,10 @@ public void EnsureHandlerCreated(Action<MauiAppBuilder> additionalCreationAction | |||
var appBuilder = MauiApp | |||
.CreateBuilder(); | |||
|
|||
appBuilder.Services.AddSingleton<IDispatcherProvider>(svc => TestDispatcher.Provider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was to fix some issue that only happens in some environments. I updated this setup code to match what other tests do.
// It's possible that the DOMContentLoaded event won't fire because it's already loaded by the time we got here. To check | ||
// for that, we inspect an arbitrary custom HTML element attribute to see if we can find it. If we can find it, then surely | ||
// the DOM content is loaded, so we can continue with the test. | ||
var testHtmlLoadedAttributeValue = await wv2.CoreWebView2.ExecuteScriptAsync("(document.head.attributes['testhtmlloaded']?.value === 'true')"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix.
@dotnet/dotnet-maui-blazor-eng - need one of you to sign off as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the DOMContentLoaded
fix but don't know what the other changes are for. It sounds like you know what you're doing though.
The other fixes were to simply make the tests work on Windows at all. These tests previously never ran on Windows (MAUI tests only ran on Android/iOS devices). At some point various MAUI test projects were updated to work on Windows, but not the Blazor ones. Part of the changes in this PR are to bring the Blazor tests up-to-date with other MAUI tests (I just copied their setup code). |
@SteveSandersonMS said:
The highest compliment 😁 But maybe I have you fooled?? |
It seems that the test sometimes waits for an event that already happened, so it doesn't see it happen, and fails. I added a check to evaluate the state of the test to see if it doesn't need to wait for the event and allows the test to continue.
Fixes #16187