-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
IApp.cs
69 lines (57 loc) · 1.72 KB
/
IApp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace UITest.Core
{
public interface IApp : IDisposable
{
IConfig Config { get; }
IUIElementQueryable Query { get; }
ApplicationState AppState { get; }
IUIElement FindElement(string id);
IUIElement FindElement(IQuery query);
IReadOnlyCollection<IUIElement> FindElements(string id);
IReadOnlyCollection<IUIElement> FindElements(IQuery query);
string ElementTree { get; }
ICommandExecution CommandExecutor { get; }
}
public interface IScreenshotSupportedApp : IApp
{
FileInfo Screenshot(string fileName);
byte[] Screenshot();
}
public interface ILogsSupportedApp : IApp
{
IEnumerable<string> GetLogTypes();
IEnumerable<string> GetLogEntries(string logType);
}
public static class AppExtensions
{
public static void Click(this IApp app, float x, float y)
{
app.CommandExecutor.Execute("click", new Dictionary<string, object>()
{
{ "x", x },
{ "y", y }
});
}
internal static T As<T>(this IApp app)
where T : IApp
{
if (app is not T derivedApp)
throw new NotImplementedException($"The app '{app}' does not implement '{typeof(T).FullName}'.");
return derivedApp;
}
}
public static class ScreenshotSupportedAppExtensions
{
public static FileInfo Screenshot(this IApp app, string fileName) =>
app.As<IScreenshotSupportedApp>().Screenshot(fileName);
public static byte[] Screenshot(this IApp app) =>
app.As<IScreenshotSupportedApp>().Screenshot();
}
public static class LogsSupportedAppExtensions
{
public static IEnumerable<string> GetLogTypes(this IApp app) =>
app.As<ILogsSupportedApp>().GetLogTypes();
public static IEnumerable<string> GetLogEntries(this IApp app, string logType) =>
app.As<ILogsSupportedApp>().GetLogEntries(logType);
}
}