diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CarouselViewItemsShouldRenderVertically.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CarouselViewItemsShouldRenderVertically.png index 2843b230f1b4..d5b25535eae7 100644 Binary files a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CarouselViewItemsShouldRenderVertically.png and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/CarouselViewItemsShouldRenderVertically.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28930.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28930.cs index 183c248aa331..3b84a3292912 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28930.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28930.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_WINDOWS + +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -19,8 +21,13 @@ public void LineBreakModeInCarouselViewShouldWork() App.WaitForElement("dotnetbot3"); App.WaitForElement("dotnetbot4"); - App.ScrollRight("MyCarousel", swipePercentage: 0.7, swipeSpeed: 200); + App.ScrollRight("MyCarousel", swipePercentage: 0.9, swipeSpeed: 200); - App.WaitForTextToBePresentInElement("ItemLabel", "Item 2"); + if (!App.WaitForTextToBePresentInElement("ItemLabel", "Item 2")) + { + Assert.Fail("Item 2 not found"); + } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs index d8e72e9f864d..bb5d0a70fc70 100644 --- a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs +++ b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Drawing; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Android.Enums; @@ -91,6 +92,20 @@ public static void PressDown(this IApp app, string element) return (string?)response.Value; } + public static bool TryGetText(this IUIElement element, [NotNullWhen(true)] out string? text) + { + try + { + text = GetText(element); + return text != null; + } + catch + { + text = null; + return false; + } + } + public static string? ReadText(this IUIElement element) => element.GetText(); @@ -799,7 +814,8 @@ public static bool WaitForTextToBePresentInElement(this IApp app, string automat while (true) { var element = app.FindElements(automationId).FirstOrDefault(); - if (element != null && (element.GetText()?.Contains(text, StringComparison.OrdinalIgnoreCase) ?? false)) + + if (element != null && element.TryGetText(out var s) && s.Contains(text, StringComparison.OrdinalIgnoreCase)) { return true; }