-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Testing] Fix flaky EntryClearButtonShouldBeVisibleOnDarkTheme test #34341
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,16 +40,20 @@ public void EntryClearButtonShouldBeVisibleOnDarkTheme() | |
| { | ||
| App.WaitForElement("TestEntry"); | ||
| App.Tap("ThemeButton"); | ||
|
|
||
| // Wait for the theme change to propagate through the UI | ||
| App.WaitForTextToBePresentInElement("ThemeLabel", "Dark"); | ||
|
|
||
| #if WINDOWS // On Windows, the clear button isn't visible when Entry loses focus, so manually focused to check its icon color. | ||
| App.Tap("TestEntry"); | ||
| #endif | ||
|
|
||
| #if IOS | ||
| // On iOS, the virtual keyboard appears inconsistent with keyboard characters casing, can cause flaky test results. As this test verifying only the entry clear button color, crop the bottom portion of the screenshot to exclude the keyboard. | ||
| // Using DismissKeyboard() would unfocus the control in iOS, so we're using cropping instead to maintain focus during testing. | ||
| VerifyScreenshot(cropBottom: 1550); | ||
| VerifyScreenshot(cropBottom: 1550, retryTimeout: TimeSpan.FromSeconds(3)); | ||
| #else | ||
| VerifyScreenshot(); | ||
| VerifyScreenshot(retryTimeout: TimeSpan.FromSeconds(3)); | ||
|
Comment on lines
+54
to
+56
|
||
| #endif | ||
| } | ||
| } | ||
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.
The
_themeLabel.Text = "Dark"update inButton_Clickedhappens synchronously right afterApplication.Current.UserAppTheme = newTheme, but on Windows the actual WinUI visual theme propagation usesDispatcherQueue.TryEnqueue(seeApplication.Windows.cs:105), which is an asynchronous dispatch. SoWaitForTextToBePresentInElement("ThemeLabel", "Dark")only confirms the MAUI-level property assignment occurred; it does not guarantee that the WinUIRequestedThemeupdate and the subsequent re-render of child controls (e.g., the Entry's clear button color) have completed.As a result, the test can still take a screenshot mid-theme-render on Windows. The
retryTimeout: TimeSpan.FromSeconds(3)onVerifyScreenshotis the real mechanism compensating for this. To make the label a stronger synchronization point, its text should be updated after awaiting the theme change, or inside aRequestedThemeChangedcallback rather than synchronously after settingUserAppTheme. As an alternative, aRequestedThemeChangedevent onApplication.Currentcould set the label text when the theme change is actually applied.Note: If the
retryTimeoutalone is considered sufficient, theThemeLabelapproach is still useful as it reduces unnecessary wait time on fast machines—but in that case the comment "deterministic signal" in the PR description slightly overstates the guarantee provided.