Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WaitForAndLog and WaitForAndTap extension methods #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
56 changes: 56 additions & 0 deletions src/Plugin.Maui.UITestHelpers.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,62 @@ public static bool WaitForTextToBePresentInElement(this IApp app, string automat
}
}

public static IUIElement? WaitForAndLog(this IApp app, string elementId, TimeSpan? timeout = null)
{
string beforeMessage = $"Waiting for {elementId} - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(beforeMessage);
var result = app.WaitForElement(elementId, beforeMessage, timeout);
string afterMessage = $"Found {elementId} - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(afterMessage);
try
{
if (result is not null && result.IsDisplayed())
{
Console.WriteLine($"{elementId} was visible");
return (IUIElement?)result;
}
else
{
Console.WriteLine($"{elementId} was not visible");
return null;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException?.Message.ToString());
Console.WriteLine($"{elementId} was not visible and threw an exception");
return null;
}
}

/// <summary>
/// Method that waits for element to be visible, selects element that is visible then taps.
/// </summary>
/// <param name="automationId"></param>
/// <param name="delay"></param>
public static void WaitForAndTap(this IApp app, string automationId, int? delay = null)
{
var element = WaitForAndLog(app, automationId);

if (element is null)
{
string nullElement = $"Element with id '{automationId} was null' - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(nullElement);
throw new NullReferenceException();
}
string beforeMessage = $"Will tap element: '{automationId}' - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(beforeMessage);
element.Tap();
string afterMessage = $"Tapped element: ' {automationId}' - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(afterMessage);
if (delay is not null)
{
Task.Delay(delay.Value).Wait();
string delayMessage = $"Delayed after tapping element: ' {automationId}' - {DateTime.Now.ToString("HH:mm:ss")}";
Console.WriteLine(delayMessage);
}
}

/// <summary>
/// Presses the volume up button on the device.
/// </summary>
Expand Down