48 строки
1.3 KiB
C#
48 строки
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Microsoft.Maui.Automation
|
|
{
|
|
public class MultiPlatformApplication : Application
|
|
{
|
|
public MultiPlatformApplication(Platform defaultPlatform, params (Platform platform, IApplication app)[] apps)
|
|
{
|
|
DefaultPlatform = defaultPlatform;
|
|
|
|
PlatformApps = new Dictionary<Platform, IApplication>();
|
|
|
|
foreach (var app in apps)
|
|
PlatformApps[app.platform] = app.app;
|
|
}
|
|
|
|
public readonly IDictionary<Platform, IApplication> PlatformApps;
|
|
|
|
|
|
public override Platform DefaultPlatform { get; }
|
|
|
|
IApplication GetApp(Platform platform)
|
|
{
|
|
if (!PlatformApps.ContainsKey(platform))
|
|
throw new PlatformNotSupportedException();
|
|
|
|
return PlatformApps[platform];
|
|
}
|
|
|
|
public override Task<IEnumerable<Element>> GetElements()
|
|
=> GetApp(DefaultPlatform).GetElements();
|
|
|
|
public override Task<string> GetProperty(string elementId, string propertyName)
|
|
=> GetApp(DefaultPlatform).GetProperty(elementId, propertyName);
|
|
|
|
public override Task<IEnumerable<Element>> FindElements(Predicate<Element> matcher)
|
|
=> GetApp(DefaultPlatform).FindElements(matcher);
|
|
|
|
|
|
public override Task<PerformActionResult> PerformAction(string action, string elementId, params string[] arguments)
|
|
=> GetApp(DefaultPlatform).PerformAction(action, elementId, arguments);
|
|
|
|
}
|
|
}
|
|
|