From 73f35462c2c06711ef43d6821f06048265808f92 Mon Sep 17 00:00:00 2001 From: Shane Date: Wed, 4 Mar 2026 17:25:33 -0600 Subject: [PATCH] Fix flaky EntryClearButtonShouldBeVisibleOnDarkTheme test The dark theme screenshot test fails in 67% of PR builds (61/91) with a consistent 13% image difference. The root cause is a race condition: after tapping ThemeButton to switch to dark mode, the VerifyScreenshot call fires before the WinUI theme transition completes. Changes: - HostApp: Add hidden ThemeLabel that updates text on theme change, providing a deterministic signal that the theme switch completed - Test: Wait for ThemeLabel text to show 'Dark' before proceeding - Test: Add retryTimeout of 3 seconds to VerifyScreenshot to handle any remaining rendering delay after theme propagation This follows the same pattern used by AppThemeFeatureTests which also uses retryTimeout for theme-change screenshot verification. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../tests/TestCases.HostApp/Issues/Issue32886.cs | 15 ++++++++++++++- .../Tests/Issues/Issue32886.cs | 8 ++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32886.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue32886.cs index b9f5498ed4d3..a58195201963 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue32886.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32886.cs @@ -3,6 +3,8 @@ namespace Maui.Controls.Sample.Issues; [Issue(IssueTracker.Github, 32886, "[Android, iOS, Mac] Entry ClearButton not visible on dark theme", PlatformAffected.Android | PlatformAffected.iOS | PlatformAffected.macOS)] public class Issue32886 : TestContentPage { + Label _themeLabel; + protected override void Init() { Title = "Issue32886"; @@ -25,9 +27,18 @@ protected override void Init() }; button.Clicked += Button_Clicked; + _themeLabel = new Label + { + Text = "Light", + AutomationId = "ThemeLabel", + HeightRequest = 0, + Opacity = 0 + }; + var layout = new VerticalStackLayout(); layout.Children.Add(entry); layout.Children.Add(button); + layout.Children.Add(_themeLabel); Content = layout; @@ -39,7 +50,9 @@ private void Button_Clicked(object sender, EventArgs e) { if (Application.Current is not null) { - Application.Current.UserAppTheme = Application.Current.UserAppTheme != AppTheme.Dark ? AppTheme.Dark : AppTheme.Light; + var newTheme = Application.Current.UserAppTheme != AppTheme.Dark ? AppTheme.Dark : AppTheme.Light; + Application.Current.UserAppTheme = newTheme; + _themeLabel.Text = newTheme == AppTheme.Dark ? "Dark" : "Light"; } } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32886.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32886.cs index 9cadff37384f..a18ef47da308 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32886.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32886.cs @@ -40,6 +40,10 @@ 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 @@ -47,9 +51,9 @@ public void EntryClearButtonShouldBeVisibleOnDarkTheme() #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)); #endif } } \ No newline at end of file