Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NUnit.Framework;
#if TEST_FAILS_ON_WINDOWS

using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -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");
}
}
}
}

#endif
18 changes: 17 additions & 1 deletion src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
Expand Down
Loading