Skip to content

Commit 165bc49

Browse files
[Testing] Fix for flaky UITests in CI - 3 (#33178)
This pull request improves the reliability and accuracy of UI tests by addressing test flakiness, enhancing assertions, and refining test logic. The main focus is on making tests more robust across different platforms (especially in CI environments) and ensuring UI behavior is correctly validated. **Test reliability improvements:** * Added retry logic for drag-and-drop actions in `GesturesSenderIsView()` on Mac Catalyst to reduce test flakiness in CI environments. * Extended double-tap retry logic in `TapThenDoubleTap()` to both Android and iOS platforms, not just Android, to handle potential flakiness. **Test accuracy and validation enhancements:** * Improved `ModalPageMarginCorrectAfterKeyboardOpens()` by capturing and asserting the position of an `Entry` before and after keyboard appearance/dismissal, ensuring the UI remains visible and returns to its original state. * Updated `TextInEditorShouldScroll()` to use a more precise scroll command (`ScrollStrategy.Gesture` with `withInertia: false`), improving test consistency.
1 parent 30b9029 commit 165bc49

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue17531.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ public void GesturesSenderIsView()
2222
App.WaitForElement("Red");
2323
App.WaitForElement("Green");
2424
App.DragAndDrop("Red", "Green");
25+
26+
#if MACCATALYST // In CI DragAndDrop does not effective sometimes so retry once before failing to resolve the flakiness.
27+
28+
try
29+
{
30+
App.WaitForElement("DropResultLabel");
31+
}
32+
catch (TimeoutException)
33+
{
34+
App.DragAndDrop("Red", "Green");
35+
}
36+
#endif
37+
App.WaitForElement("DropResultLabel");
2538
var dropResultLabel = App.FindElement("DropResultLabel").GetText();
2639
Assert.That(dropResultLabel, Is.EqualTo("Success"));
2740
}

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18961.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,33 @@ public async Task ModalPageMarginCorrectAfterKeyboardOpens()
2929
await Task.Delay(1000); // Wait for the scroll animation to finish.
3030
App.ScrollDown("TestScrollView"); // Ensure that we are at the end of the scroll.
3131

32-
// 3. Focus latest Entry
32+
// 3. Get initial position of the Entry before keyboard opens
3333
App.WaitForElement(LastEntry);
34+
var initialRect = App.FindElement(LastEntry).GetRect();
35+
36+
// 4. Focus latest Entry and enter text
3437
App.EnterText(LastEntry, "test");
3538
App.Click(LastEntry);
3639
await Task.Delay(1000);
3740

38-
// 4. The keyboard has opened and the Entry have been translated above the keyboard.
39-
App.Screenshot("The keyboard has opened and the Entry have been translated above the keyboard.");
40-
VerifyScreenshot();
41+
// 5. Verify the Entry is still visible (not covered by keyboard)
42+
// The Entry should be repositioned above the keyboard
43+
var entryWithKeyboard = App.FindElement(LastEntry).GetRect();
44+
Assert.That(entryWithKeyboard.Y, Is.LessThan(initialRect.Y),
45+
"Entry should be moved up when keyboard appears to remain visible");
4146

42-
// 5. Close the keyboard to see if sizes adjust back.
47+
// 6. Close the keyboard to see if sizes adjust back.
4348
App.DismissKeyboard();
4449
await Task.Delay(1000);
4550

46-
// 6. Verify the latest Entry text.
51+
// 7. Verify the latest Entry text was preserved.
4752
var text = App.FindElement(LastEntry).GetText();
4853
Assert.That(text, Is.EqualTo("test"));
4954

50-
// 7. Make sure that everything has returned to the initial size once the keyboard has closed.
51-
App.Screenshot("Make sure that everything has returned to the initial size once the keyboard has closed.");
55+
// 8. Verify Entry returns to approximately its original position after keyboard dismissal
56+
var finalRect = App.FindElement(LastEntry).GetRect();
57+
Assert.That(Math.Abs(finalRect.Y - initialRect.Y), Is.LessThan(5),
58+
"Entry should return close to its original position after keyboard dismissal");
5259
}
5360
}
5461
}

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19500.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public Issue19500(TestDevice device) : base(device)
1919
public void TextInEditorShouldScroll()
2020
{
2121
var yPosLabel = App.WaitForElement(yPositionLabel);
22-
App.ScrollDown("editor");
22+
App.ScrollDown("editor", ScrollStrategy.Gesture, withInertia: false);
2323
#if MACCATALYST
2424
App.ScrollDown("editor"); // To make sure the editor is scrolled down
2525
var yPos = yPosLabel.GetText();

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24574.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public void TapThenDoubleTap()
2626

2727
App.DoubleTap("TapLabel");
2828

29-
#if ANDROID
30-
// In CI Double tap does not effective sometimes so retry once before failing to resolve the flakiness.
29+
#if ANDROID || IOS // In CI Double tap does not effective sometimes so retry once before failing to resolve the flakiness.
30+
3131
try
3232
{
3333
App.WaitForElement("Double");

0 commit comments

Comments
 (0)