-
Notifications
You must be signed in to change notification settings - Fork 17
/
QueryExtensions.cs
163 lines (114 loc) · 6.75 KB
/
QueryExtensions.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using Microsoft.Maui.Automation.Querying;
namespace Microsoft.Maui.Automation;
public static class QueryExtensions
{
public static Query ThenBy(this Query query, Predicate<IElement> predicate)
=> query.Append(predicate);
public static Query ThenByAutomationId(this Query query, string automationId)
=> query.Append(e => e.AutomationId == automationId);
public static Query ThenById(this Query query, string id)
=> query.Append(e => e.Id == id);
public static Query ThenOfType(this Query query, string typeName)
=> query.Append(e => e.Type == typeName);
public static Query ThenOfFullType(this Query query, string fullTypeName)
=> query.Append(e => e.FullType == fullTypeName);
public static Query ThenContainingText(this Query query, string text, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> query.Append(e => e.Text.Contains(text, comparisonType));
public static Query ThenMarked(this Query query, string marked, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> query.Append(e => e.Id.Equals(marked, comparisonType)
|| e.AutomationId.Equals(marked, comparisonType)
|| e.Text.Equals(marked, comparisonType));
public static Query Siblings(this Query query, Predicate<IElement>? predicate = null)
=> query.Append(new SiblingsQueryStep(predicate));
public static Query AtIndex(this Query query, int index)
=> query.Append(new IndexQueryStep(index));
public static Query Tap(this Query query)
=> query.Append(new InteractionQueryStep((driver, element) => driver.Tap(element)));
public static Query LongPress(this Query query)
=> query.Append(new InteractionQueryStep((driver, element) => driver.LongPress(element)));
public static Query InputText(this Query query, string text)
=> query.Append(new InteractionQueryStep((driver, element) => driver.InputText(element, text)));
public static Query ClearText(this Query query, string text)
=> query.Append(new InteractionQueryStep((driver, element) => driver.ClearText(element)));
}
public static class DriverQueryExtensions
{
static DriverQuery AppendChildren(this DriverQuery query, Predicate<IElement> predicate)
{
query.Query.Append(predicate);
return query;
}
static DriverQuery Append(this DriverQuery query, IQueryStep step)
{
query.Query.Append(step);
return query;
}
public static DriverQuery By(this DriverQuery query, Predicate<IElement>? predicate = null)
=> query.Append(new DescendantsQueryStep(predicate));
public static DriverQuery AutomationId(this DriverQuery query, string automationId)
=> query.By(e => e.AutomationId == automationId);
public static DriverQuery Id(this DriverQuery query, string id)
=> query.By(e => e.Id == id);
public static DriverQuery Type(this DriverQuery query, string typeName)
=> query.By(e => e.Type == typeName);
public static DriverQuery FullType(this DriverQuery query, string fullTypeName)
=> query.By(e => e.FullType == fullTypeName);
public static DriverQuery Text(this DriverQuery query, string text, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> query.By(e => e.Text.Equals(text, comparisonType));
public static DriverQuery ContainsText(this DriverQuery query, string text, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> query.By(e => e.Text.Contains(text, comparisonType));
public static DriverQuery Marked(this DriverQuery query, string marked, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> query.By(e => e.Id.Equals(marked, comparisonType)
|| e.AutomationId.Equals(marked, comparisonType)
|| e.Text.Equals(marked, comparisonType));
public static DriverQuery First(this DriverQuery query)
=> query.Append(new FirstQueryStep());
public static DriverQuery Children(this DriverQuery query, Predicate<IElement> predicate)
=> query.AppendChildren(predicate);
public static DriverQuery ChildrenByAutomationId(this DriverQuery query, string automationId)
=> query.AppendChildren(e => e.AutomationId == automationId);
public static DriverQuery ChildrenById(this DriverQuery query, string id)
=> query.AppendChildren(e => e.Id == id);
public static DriverQuery ChildrenOfType(this DriverQuery query, string typeName)
=> query.AppendChildren(e => e.Type == typeName);
public static DriverQuery ChildrenOfFullType(this DriverQuery query, string fullTypeName)
=> query.AppendChildren(e => e.FullType == fullTypeName);
public static DriverQuery ChildrenContainingText(this DriverQuery query, string text, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> query.AppendChildren(e => e.Text.Contains(text, comparisonType));
public static DriverQuery ChildrenMarked(this DriverQuery query, string marked, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> query.AppendChildren(e => e.Id.Equals(marked, comparisonType)
|| e.AutomationId.Equals(marked, comparisonType)
|| e.Text.Equals(marked, comparisonType));
public static DriverQuery Siblings(this DriverQuery query, Predicate<IElement>? predicate = null)
=> query.Append(new SiblingsQueryStep(predicate));
public static DriverQuery Index(this DriverQuery query, int index)
=> query.Append(new IndexQueryStep(index));
public static DriverQuery Tap(this DriverQuery query)
=> query.Append(new InteractionQueryStep((driver, element) => driver.Tap(element)));
public static DriverQuery LongPress(this DriverQuery query)
=> query.Append(new InteractionQueryStep((driver, element) => driver.LongPress(element)));
public static DriverQuery InputText(this DriverQuery query, string text)
=> query.Append(new InteractionQueryStep((driver, element) => driver.InputText(element, text)));
public static DriverQuery ClearText(this DriverQuery query, string text)
=> query.Append(new InteractionQueryStep((driver, element) => driver.ClearText(element)));
}
public static class On
{
public static Query Platform(Platform automationPlatform)
=> Query.On(automationPlatform);
}
public static class By
{
public static Query AutomationId(string automationId)
=> Query.By(e => e.AutomationId == automationId);
public static Query Id(string id)
=> Query.By(e => e.Id == id);
public static Query Type(string type)
=> Query.By(e => e.Type == type);
public static Query ContainingText(string text, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> Query.By(e => e.Text.Contains(text, comparisonType));
public static Query Marked(string marked, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
=> Query.By(e => e.Id.Equals(marked, comparisonType)
|| e.AutomationId.Equals(marked, comparisonType)
|| e.Text.Equals(marked, comparisonType));
}