-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Testing] Fix for flaky UITests in CI - 3 #33689
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
base: main
Are you sure you want to change the base?
[Testing] Fix for flaky UITests in CI - 3 #33689
Conversation
|
Hey there @@TamilarasanSF4853! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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.
Pull request overview
Improves UI test reliability by adding retries/synchronization and adjusting cookie retrieval logic for Android.
Changes:
- Add an NUnit retry to reduce flakiness in the SafeArea border orientation test.
- Add extra synchronization between taps in a rotation regression test.
- Add an Android-specific cookie retrieval path in the HostApp issue page.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28986_SafeAreaBorderOrientation.cs | Adds [Retry(2)] to mitigate intermittent failures during repeated orientation changes. |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18420.cs | Adds additional WaitForElement calls to stabilize repeated tap interactions. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue18452.cs | Minor formatting/newline change only. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue12134.cs | Adds Android cookie retrieval via Android.Webkit.CookieManager instead of JS evaluation. |
| private async void WebViewOnNavigated(object sender, WebNavigatedEventArgs e) | ||
| { | ||
| #if ANDROID | ||
| var result = Android.Webkit.CookieManager.Instance?.GetCookie("https://dotnet.microsoft.com"); | ||
| #else |
Copilot
AI
Jan 23, 2026
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.
WebViewOnNavigated is marked async, but under #if ANDROID there is no await, which produces CS1998. This repo sets TreatWarningsAsErrors=true (see Directory.Build.props:16), so Android builds will fail. Consider restructuring so the method always awaits (e.g., wrap the Android cookie lookup in a Task and await it), or conditional-compile a non-async Android handler.
| #else | ||
| var result = await ((WebView)sender).EvaluateJavaScriptAsync("document.cookie"); | ||
| #endif | ||
| _label.Text = result.Contains(_guid.ToString(), StringComparison.OrdinalIgnoreCase) ? "Success" : "Failed"; |
Copilot
AI
Jan 23, 2026
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.
Android.Webkit.CookieManager.Instance?.GetCookie(...) can return null (or the Instance can be null), and the next line calls result.Contains(...), which will throw on Android. Please make the check null-safe and treat null/empty as "Failed".
| _label.Text = result.Contains(_guid.ToString(), StringComparison.OrdinalIgnoreCase) ? "Success" : "Failed"; | |
| var success = !string.IsNullOrEmpty(result) && result.Contains(_guid.ToString(), StringComparison.OrdinalIgnoreCase); | |
| _label.Text = success ? "Success" : "Failed"; |
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
PureWeen
left a comment
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.
looks like CookiesCorrectlyLoadWithMultipleWebViews failed
@PureWeen Restricted the CookiesCorrectlyLoadWithMultipleWebViews test for Android. |
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…33749) > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description This PR improves the reliability of several flaky UI tests by: 1. **Replacing `Thread.Sleep` with `retryTimeout`** - The `retryTimeout` parameter keeps retrying screenshot comparisons until they match or timeout, adapting to actual UI timing across different machines/load conditions. 2. **Fixing Issue10563 SwipeView button animations** - Added flat `Background = SolidColorBrush(Colors.LightGray)` to buttons to prevent ripple animation artifacts that caused visual differences on CI. ## Changes | Test | Issue | Fix | |------|-------|-----| | Issue10563 | Button ripple animation artifacts in SwipeView test | Flat button background + updated baselines | | Issue18857 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue24856 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue25192 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue27418 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue28657 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue30575 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(3)` | ## Related PRs (not overlapping) - #33737 - Fixes Issue18751/18896 (local monkey images) - #33689 - Fixes Issue12134 (WebView cookies) --------- Co-authored-by: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com>
…otnet#33749) > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description This PR improves the reliability of several flaky UI tests by: 1. **Replacing `Thread.Sleep` with `retryTimeout`** - The `retryTimeout` parameter keeps retrying screenshot comparisons until they match or timeout, adapting to actual UI timing across different machines/load conditions. 2. **Fixing Issue10563 SwipeView button animations** - Added flat `Background = SolidColorBrush(Colors.LightGray)` to buttons to prevent ripple animation artifacts that caused visual differences on CI. ## Changes | Test | Issue | Fix | |------|-------|-----| | Issue10563 | Button ripple animation artifacts in SwipeView test | Flat button background + updated baselines | | Issue18857 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue24856 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue25192 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue27418 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue28657 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(2)` | | Issue30575 | Thread.Sleep causes flakiness | `retryTimeout: TimeSpan.FromSeconds(3)` | ## Related PRs (not overlapping) - dotnet#33737 - Fixes Issue18751/18896 (local monkey images) - dotnet#33689 - Fixes Issue12134 (WebView cookies) --------- Co-authored-by: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com>
This pull request includes targeted improvements to test reliability and platform-specific code handling in the test suite. The main changes address platform differences for cookie retrieval and enhance test stability by adding retries and synchronization points.
Platform-specific handling:
CookiesCorrectlyLoadWithMultipleWebViewstest, an Android-specific code path was added to retrieve cookies using Android.Webkit.CookieManager.Instance?.GetCookie, while other platforms continue to use EvaluateJavaScriptAsync. This ensures correct cookie retrieval behaviour on Android.Test stability improvements:
SafeAreaBorderMultipleOrientationChangestest, the [Retry(2)] attribute was added to reduce flakiness by retrying failed tests up to two times.ApplyingRotationWithZeroDurationShouldNotCrashtest, an additional App.WaitForElement("RotateButton") was inserted to ensure UI stability before proceeding with the next action.