[Testing] Fix for flaky test(VerifyEditorFocusedEvent) in CI#31895
[Testing] Fix for flaky test(VerifyEditorFocusedEvent) in CI#31895jfversluis merged 1 commit intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
Stabilizes a flaky UI test by converting it to async and inserting a delay to allow the focus event to propagate before assertion.
- Change test signature to async Task to support awaiting operations
- Insert 100 ms Task.Delay after tapping the editor to mitigate timing race
- Preserve existing assertion logic for the Focused event label
| { | ||
| App.WaitForElement("TestEditor"); | ||
| App.Tap("TestEditor"); | ||
| await Task.Delay(100); |
There was a problem hiding this comment.
Using a fixed delay introduces a magic number and can remain flaky on slower CI agents while adding unnecessary wait on fast machines. Prefer a condition-based wait/poll that exits as soon as the label reflects the focused state, e.g., loop with small delays until App.WaitForElement("FocusedLabel").GetText() == "Focused: Event Triggered" or timeout. This removes the arbitrary 100 ms constant and makes the test both faster and more reliable.
There was a problem hiding this comment.
I m not sure just adding the delay is going to work, do we have another way to know the keyboard is dismissed ? is there a event that fires when the keyboard is hidden ?
There was a problem hiding this comment.
Hi @rmarinho, similar delay adjustments were added in .NET 10 to dismiss the keyboard on CI. Therefore, I used the same approach in the Main branch, and the test has now passed in this PR.
.NET 10 Code reference :
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
b68c8f6 to
b042bf7
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| { | ||
| App.WaitForElement("TestEditor"); | ||
| App.Tap("TestEditor"); | ||
| await Task.Delay(100); |
There was a problem hiding this comment.
Could include a Label in the sample, and verify the text ("Focused Editor" for example). Also, before close the keyboard, can use
?There was a problem hiding this comment.
Hi @jsuarezruiz, I have added isKeyboardShown method to the test and the label were already added to the sample to verify that the focused editor event is triggered correctly.
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
8894139 to
3df4086
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
3df4086 to
e821c1d
Compare
This pull request updates the
VerifyEditorFocusedEventtest method to be asynchronous, improving reliability by adding a short delay after tapping the editor. This ensures the focus event is properly triggered before the assertion is made.Test reliability improvement:
VerifyEditorFocusedEventinEditorFeatureTests.csto be anasync Task, and added aTask.Delay(100)after tapping the editor to ensure the focus event has time to trigger before the test assertion.