Skip to content

Commit

Permalink
[Testing] Fix flaky UITests failing sometimes 1 (#27091)
Browse files Browse the repository at this point in the history
* Fix flaky UITests failing sometimes on CI

* Fix Issue899TestsAppCrashWhenSwitchingTabs on Android

* Fixed Issue889 test on Windows
  • Loading branch information
jsuarezruiz authored Jan 16, 2025
1 parent 6f45ae6 commit 1a4f263
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Bugzilla59925 : _IssuesUITest
{
const string BiggerButton = "BiggerButton";
const string TestEntry = "TestEntry";

public Bugzilla59925(TestDevice testDevice) : base(testDevice)
{
}
Expand All @@ -17,33 +20,36 @@ public Bugzilla59925(TestDevice testDevice) : base(testDevice)
[Category(UITestCategories.Compatibility)]
public void Bugzilla59925Test()
{
App.WaitForElement("BiggerButton");
var intialSize = App.WaitForElement("TestEntry").GetRect().Height;
App.WaitForElement(BiggerButton);
var initialSize = App.WaitForElement(TestEntry).GetRect().Height;

// iOS/macOS Catalyst Workaround: Minimum Height Threshold
// Issue: Entry control has a minimum vertical height on these platforms.
// Impact: Font size increases don't affect height until exceeding this threshold.
// Solution: Perform additional taps to ensure font size surpasses the minimum.
// This allows subsequent size comparisons to accurately reflect height changes.
#if IOS || MACCATALYST
for (int i = 0; i < 8; i++)
for (int i = 0; i < 10; i++)
{
App.WaitForElement("BiggerButton");
App.Tap("BiggerButton");
App.WaitForElement(BiggerButton);
App.Tap(BiggerButton);
}
#endif

App.Tap("BiggerButton");
var updatedSize = App.WaitForElement("TestEntry").GetRect().Height;
Assert.That(updatedSize, Is.GreaterThan(intialSize));

App.Tap("BiggerButton");
var updatedSize1 = App.WaitForElement("TestEntry").GetRect().Height;
Assert.That(updatedSize1, Is.GreaterThan(updatedSize));

App.Tap("BiggerButton");
var updatedSize2 = App.WaitForElement("TestEntry").GetRect().Height;
Assert.That(updatedSize2, Is.GreaterThan(updatedSize1));
App.WaitForElement(BiggerButton);
App.DoubleTap(BiggerButton);
var updatedSize1 = App.WaitForElement(TestEntry).GetRect().Height;
Assert.That(updatedSize1, Is.GreaterThanOrEqualTo(initialSize));

App.WaitForElement(BiggerButton);
App.DoubleTap(BiggerButton);
var updatedSize2 = App.WaitForElement(TestEntry).GetRect().Height;
Assert.That(updatedSize2, Is.GreaterThanOrEqualTo(updatedSize1));

App.WaitForElement(BiggerButton);
App.DoubleTap(BiggerButton);
var updatedSize3 = App.WaitForElement(TestEntry).GetRect().Height;
Assert.That(updatedSize3, Is.GreaterThanOrEqualTo(updatedSize2));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public void VerifyLabelSpanGestureWhenWrappedOverTwoLines()
{
var label = App.WaitForElement("Label");
var location = label.GetRect();
var height = location.Height / 2;
var endOfFirstLine = location.X + location.Width - 150;
App.Click(endOfFirstLine, location.Y + height);
var middleHeight = location.Height / 2;
const int marginRight = 150;
var endOfFirstLine = location.X + location.Width - marginRight;
var testlabel = App.WaitForElement("TestLabel");
App.Click(endOfFirstLine, location.Y + middleHeight);
Assert.That(testlabel.GetText(), Is.EqualTo("Label span tapped"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public Issue25889(TestDevice device) : base(device)
public void RemainingItemsThresholdReachedCommandFired()
{
App.WaitForElement("collectionView");
App.ScrollDown("collectionView");
App.ScrollDown("collectionView", ScrollStrategy.Gesture);

App.WaitForElement("collectionView");
App.ScrollDown("collectionView", ScrollStrategy.Gesture);

var label = App.WaitForElement("mainPageLabel");
Assert.That(label.GetText(), Is.EqualTo("Command Fired!"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue889 : _IssuesUITest
{
const string Tab2Title = "Tab 2 Title";
string _tab2Title = "Tab 2 Title";

public Issue889(TestDevice testDevice) : base(testDevice)
{
}
Expand All @@ -20,14 +21,26 @@ public void Issue899TestsAppCrashWhenSwitchingTabs()
App.WaitForElement("PushPage");
App.Tap("PushPage");
App.WaitForElement("PushedPageLabel");

#if IOS || MACCATALYST
App.Tap(AppiumQuery.ByName("Initial Page"));
var initialPageQuery = AppiumQuery.ByName("Initial Page");
App.WaitForElement(initialPageQuery);
App.Tap(initialPageQuery);
#else

#if WINDOWS
App.TapBackArrow();
#else
App.Back();
#endif

App.TapTab(Tab2Title);
#endif

#if ANDROID
_tab2Title = _tab2Title.ToUpperInvariant();
#endif
App.WaitForElement(_tab2Title);
App.TapTab(_tab2Title);
App.WaitForElement("SecondTabPageButton");
}
}

0 comments on commit 1a4f263

Please sign in to comment.