A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.5 KiB

using System;
using System.Runtime.InteropServices;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Interactions;
namespace Avalonia.IntegrationTests.Appium
{
internal static class ElementExtensions
{
public static string GetName(this AppiumWebElement element) => GetAttribute(element, "Name", "title");
public static bool? GetIsChecked(this AppiumWebElement element) =>
GetAttribute(element, "Toggle.ToggleState", "value") switch
{
"0" => false,
"1" => true,
"2" => null,
_ => throw new ArgumentOutOfRangeException($"Unexpected IsChecked value.")
};
public static void ClickListItem(this AppiumWebElement element)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
element.Click();
}
else
{
// List items don't respond to performClick on MacOS, so instead send a physical click as VoiceOver
// does.
var action = new Actions(element.WrappedDriver);
action.MoveToElement(element);
action.Click();
action.Perform();
}
}
public static string GetAttribute(AppiumWebElement element, string windows, string macOS)
{
return element.GetAttribute(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? windows : macOS);
}
}
}