Skip to content

Commit 4f0d868

Browse files
albyrock87rmarinho
authored andcommitted
Fix UI tests
1 parent 4011f42 commit 4f0d868

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed
49 Bytes
Loading

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NUnit.Framework;
1+
#if TEST_FAILS_ON_WINDOWS
2+
3+
using NUnit.Framework;
24
using UITest.Appium;
35
using UITest.Core;
46

@@ -19,8 +21,13 @@ public void LineBreakModeInCarouselViewShouldWork()
1921
App.WaitForElement("dotnetbot3");
2022
App.WaitForElement("dotnetbot4");
2123

22-
App.ScrollRight("MyCarousel", swipePercentage: 0.7, swipeSpeed: 200);
24+
App.ScrollRight("MyCarousel", swipePercentage: 0.9, swipeSpeed: 200);
2325

24-
App.WaitForTextToBePresentInElement("ItemLabel", "Item 2");
26+
if (!App.WaitForTextToBePresentInElement("ItemLabel", "Item 2"))
27+
{
28+
Assert.Fail("Item 2 not found");
29+
}
2530
}
26-
}
31+
}
32+
33+
#endif

src/TestUtils/src/UITest.Appium/HelperExtensions.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Immutable;
22
using System.Diagnostics;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Drawing;
45
using OpenQA.Selenium.Appium;
56
using OpenQA.Selenium.Appium.Android.Enums;
@@ -91,6 +92,20 @@ public static void PressDown(this IApp app, string element)
9192
return (string?)response.Value;
9293
}
9394

95+
public static bool TryGetText(this IUIElement element, [NotNullWhen(true)] out string? text)
96+
{
97+
try
98+
{
99+
text = GetText(element);
100+
return text != null;
101+
}
102+
catch
103+
{
104+
text = null;
105+
return false;
106+
}
107+
}
108+
94109
public static string? ReadText(this IUIElement element)
95110
=> element.GetText();
96111

@@ -799,7 +814,8 @@ public static bool WaitForTextToBePresentInElement(this IApp app, string automat
799814
while (true)
800815
{
801816
var element = app.FindElements(automationId).FirstOrDefault();
802-
if (element != null && (element.GetText()?.Contains(text, StringComparison.OrdinalIgnoreCase) ?? false))
817+
818+
if (element != null && element.TryGetText(out var s) && s.Contains(text, StringComparison.OrdinalIgnoreCase))
803819
{
804820
return true;
805821
}

0 commit comments

Comments
 (0)