Skip to content
Open
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
42 changes: 42 additions & 0 deletions src/Plugin.Maui.UITestHelpers.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,5 +1665,47 @@ static void WaitForNone(Func<IUIElement> query,
{
Wait(query, i => i == null, timeoutMessage, timeout, retryFrequency);
}

/// <summary>
/// Assert an element exists and is visible.
/// </summary>
public static bool DoesElementExist(this IApp app, string automationId)
{
var exists = false;

var elements = app.FindElements(automationId);
exists = elements.Count > 0;

return exists && elements.First().IsDisplayed();
}

/// <summary>
/// Assert an element found by text exists and is visible.
/// </summary>
public static IUIElement? FindVisibleElementByText(this IApp app, string text, int timeoutInSeconds = 3)
{
string beforeMessage = $"Find visible element by text: '{text}' - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(beforeMessage);

var timeout = TimeSpan.FromSeconds(timeoutInSeconds);
var stopwatch = Stopwatch.StartNew();

while (stopwatch.Elapsed < timeout)
{
var elementIsVisible = app.FindElementByText(text)?.IsDisplayed();
if (elementIsVisible is not null && elementIsVisible.Value)
{
var element = app.FindElementByText(text);
string afterMessage = $"Found visible element by text: {text} - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(afterMessage);
return element;
}
Thread.Sleep(100);
}
stopwatch.Stop();
string notVisibleMessage = $"Element with text: {text} not visible within timeout - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(notVisibleMessage);
return null;
}
}
}