summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UITests.Shared/PlatformQueries.cs
blob: aeaaf556086f84afe870101390c47d2d18216ab5 (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using System;
using System.Collections.Generic;
using Xamarin.UITest.Queries;

namespace Xamarin.Forms.Core.UITests
{
	internal static class PlatformMethodQueries
	{
#if __IOS__ || __MACOS__
		public static readonly Dictionary<BindableProperty, Tuple<string[], bool>> PropertyPlatformMethodDictionary = new Dictionary<BindableProperty, Tuple<string[], bool>> {
			{ ActivityIndicator.ColorProperty, Tuple.Create (new[] { "color" }, false) },
			{ ActivityIndicator.IsRunningProperty, Tuple.Create (new[] { "isAnimating" }, false) },
			{ Button.BorderRadiusProperty, Tuple.Create (new[] { "layer", "cornerRadius" }, false) },
			{ Button.BorderWidthProperty, Tuple.Create (new[] { "layer", "borderWidth" }, false) },
			{ Button.FontProperty, Tuple.Create (new[] { "titleLabel", "font" }, false) },
			{ Button.TextProperty, Tuple.Create (new[] { "titleLabel", "text" }, false) },
			{ Button.TextColorProperty, Tuple.Create (new[] { "titleLabel", "textColor" }, false) },
			{ View.AnchorXProperty, Tuple.Create (new[] { "layer", "transform" }, true) },
			{ View.AnchorYProperty, Tuple.Create (new[] { "layer", "transform" }, true) },
			{ View.BackgroundColorProperty, Tuple.Create (new[] { "backgroundColor" }, false) },
			{ View.IsEnabledProperty, Tuple.Create (new[] { "isEnabled" }, false) },
			{ View.OpacityProperty, Tuple.Create (new [] { "alpha" }, true) },
			{ View.RotationProperty, Tuple.Create (new[] { "layer", "transform" }, true) },
			{ View.RotationXProperty, Tuple.Create (new[] { "layer", "transform" }, true) },
			{ View.RotationYProperty, Tuple.Create (new[] { "layer", "transform" }, true) },
			{ View.ScaleProperty, Tuple.Create (new[] { "layer", "transform" }, true) },
		};

#elif __ANDROID__ || __WINDOWS__
		public static readonly Dictionary<BindableProperty, Tuple<string[], bool>> PropertyPlatformMethodDictionary = new Dictionary
			<BindableProperty, Tuple<string[], bool>>
			{
				{ ActivityIndicator.ColorProperty, Tuple.Create(new[] { "getProgressDrawable", "getColor" }, false) },
				{ ActivityIndicator.IsRunningProperty, Tuple.Create(new[] { "isIndeterminate" }, false) },
				{ Button.BorderColorProperty, Tuple.Create(new[] { "getBackground" }, false) },
				{ Button.BorderRadiusProperty, Tuple.Create(new[] { "getBackground" }, false) },
				{ Button.BorderWidthProperty, Tuple.Create(new[] { "getBackground" }, false) },
				{ Button.ImageProperty, Tuple.Create(new[] { "getBackground" }, false) },
				{ Button.FontProperty, Tuple.Create(new[] { "getTypeface", "isBold" }, false) },
				{ Button.TextProperty, Tuple.Create(new[] { "getText" }, false) },
				{ Button.TextColorProperty, Tuple.Create(new[] { "getCurrentTextColor" }, false) },
				{ View.AnchorXProperty, Tuple.Create(new[] { "getPivotX" }, true) },
				{ View.AnchorYProperty, Tuple.Create(new[] { "getPivotY" }, true) },
				{ View.BackgroundColorProperty, Tuple.Create(new[] { "getBackground", "getColor" }, true) },
				{ View.IsEnabledProperty, Tuple.Create(new[] { "isEnabled" }, false) },
				{ View.OpacityProperty, Tuple.Create(new[] { "getAlpha" }, true) },
				{ View.RotationProperty, Tuple.Create(new[] { "getRotation" }, true) },
				{ View.RotationXProperty, Tuple.Create(new[] { "getRotationX" }, true) },
				{ View.RotationYProperty, Tuple.Create(new[] { "getRotationY" }, true) },
				{ View.ScaleProperty, Tuple.Create(new[] { "getScaleX", "getScaleY" }, true) },
			};
#endif
	}

	internal static class PlatformViews
	{
#if __IOS__ || __MACOS__
		public static readonly string ActivityIndicator = "UIActivityIndicatorView";
		public static readonly string BoxView = "Xamarin_Forms_Platform_iOS_BoxRenderer";
		public static readonly string Button = "UIButton";
		public static readonly string DatePicker = "UITextField";
		public static readonly string Editor = "UITextView";
		public static readonly string Entry = "UITextField";
		public static readonly string Frame = "view:'Xamarin_Forms_Platform_iOS_FrameRenderer'";
		public static readonly string Image = "UIImageView";
		public static readonly string Label = "UILabel";
		public static readonly string ListView = "UITableView";
		public static readonly string OpenGLView = "GLKView";
		public static readonly string Picker = "UITextField";
		public static readonly string ProgressBar = "UIProgressView";
		public static readonly string SearchBar = "UISearchBar";
		public static readonly string Slider = "UISlider";
		public static readonly string Stepper = "UIStepper";
		public static readonly string Switch = "UISwitch";
		public static readonly string TableView = "UITableView";
		public static readonly string TimePicker = "UITextField";
		public static readonly string WebView = "UIWebView";
#elif __ANDROID__ || __WINDOWS__
		public static readonly string ActivityIndicator = "android.widget.ProgressBar";
		public static readonly string BoxView = "xamarin.forms.platform.android.BoxRenderer";
		public static readonly string Button = "android.widget.Button";
		public static readonly string DatePicker = "android.widget.EditText";
		public static readonly string Editor = "xamarin.forms.platform.android.EditorEditText";
		public static readonly string Entry = "xamarin.forms.platform.android.EntryEditText";
		public static readonly string Frame = "xamarin.forms.platform.android.appcompat.FrameRenderer";
		public static readonly string Image = "android.widget.ImageView";
		public static readonly string Label = "android.widget.TextView";
		public static readonly string ListView = "android.widget.ListView";
		public static readonly string OpenGLView = "android.widget.GLSurfaceView";
		public static readonly string Picker = "android.widget.EditText";
		public static readonly string ProgressBar = "android.widget.ProgressBar";
		public static readonly string SearchBar = "android.widget.SearchView";
		public static readonly string Slider = "android.widget.SeekBar";
		public static readonly string Stepper = "button marked:'+'";
		public static readonly string Switch = "android.widget.Switch";
		public static readonly string TableView = "android.widget.ListView";
		public static readonly string TimePicker = "android.widget.EditText";
		public static readonly string WebView = "android.widget.WebView";
#endif
	}

	internal static class PlatformQueries
	{
#if __IOS__ || __MACOS__
		public static readonly Func<AppQuery, AppQuery> Root = q => q.Class("UIWindow");
		public static readonly Func<AppQuery, AppQuery> RootPageListView = q => q.Class("Xamarin_Forms_Platform_iOS_ListViewRenderer index:0");
		public static readonly Func<AppQuery, AppQuery> GalleryListView = q => q.Class("Xamarin_Forms_Platform_iOS_ListViewRenderer index:1");
		public static readonly Func<AppQuery, AppQuery> PageWithoutNavigationBar = q => q.Raw("*").Index(7);
		public static readonly Func<AppQuery, AppQuery> NavigationBarBackButton = q => q.Class("UINavigationItemButtonView");

#elif __ANDROID__ || __WINDOWS__
		public static readonly Func<AppQuery, AppQuery> Root = q => q.Id("content");
		public static readonly Func<AppQuery, AppQuery> RootPageListView = q => q.Raw("ListViewRenderer index:0");
		public static readonly Func<AppQuery, AppQuery> GalleryListView = q => q.Raw("ListViewRenderer index:1");
		public static readonly Func<AppQuery, AppQuery> PageWithoutNavigationBar = q => q.Raw("* id:'content' index:0");

		public static readonly Func<AppQuery, AppQuery> NavigationBarBackButton =
			q => q.Class("android.support.v7.widget.Toolbar").Child("android.widget.ImageButton");
#endif

		// Controls
		public static readonly Func<AppQuery, AppQuery> ActivityIndicator = q => q.ClassFull(PlatformViews.ActivityIndicator);
		public static readonly Func<AppQuery, AppQuery> Button = q => q.ClassFull(PlatformViews.Button);

#if __ANDROID__
		public static Func<AppQuery, AppQuery> EntryWithPlaceholder(string text)
		{
			return q => q.Raw(string.Format("EntryEditText hint:'{0}'", text));
		}
		public static Func<AppQuery, AppQuery> EntryCellWithPlaceholder(string text)
		{
			return q => q.Raw(string.Format("EntryCellEditText hint:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EntryWithText(string text)
		{
			return q => q.Raw(string.Format("EntryEditText text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EntryCellWithText(string text)
		{
			return q => q.Raw(string.Format("EntryCellEditText text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EditorsWithText(string text)
		{
			return q => q.Raw(string.Format("EditorEditText text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EntryWithIndex(int index)
		{
			return q => q.Raw(string.Format("EntryEditText index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> SearchBarWithIndex(int index)
		{
			return q => q.Raw(string.Format("SearchView index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> LabelWithIndex(int index)
		{
			return q => q.Raw(string.Format("TextView index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> LabelWithText(string text)
		{
			return q => q.Raw(string.Format("TextView text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> LabelWithId(string id)
		{
			return q => q.Raw(string.Format("TextView id:'{0}'", id));
		}

		public static Func<AppQuery, AppQuery> PickerEntryWithIndex(int index)
		{
			return q => q.Raw(string.Format("EditText index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> PickerEntryWithPlaceholder(string placeholder)
		{
			return q => q.Raw(string.Format("EditText hint:'{0}'", placeholder));
		}

		public static Func<AppQuery, AppQuery> PickerEntryWithText(string text)
		{
			return q => q.Raw(string.Format("EditText text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> SwitchWithIndex(int index)
		{
			return q => q.Raw(string.Format("Switch index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> StepperWithIndex(int index)
		{
			return q => q.Raw(string.Format("button marked:'+' index:{0}", index));
		}

#else
		public static Func<AppQuery, AppQuery> EntryWithPlaceholder(string text)
		{
			return q => q.Raw(string.Format("TextField placeholder:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EntryWithText(string text)
		{
			return q => q.Raw(string.Format("TextField text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EntryCellWithPlaceholder(string text)
		{
			return q => q.Raw(string.Format("UITextFieldLabel text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EntryCellWithText(string text)
		{
			return q => q.Raw(string.Format("TextField text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EditorsWithText(string text)
		{
			return q => q.Raw(string.Format("TextView text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> EntryWithIndex(int index)
		{
			return q => q.Raw(string.Format("TextField index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> SearchBarWithIndex(int index)
		{
			return q => q.Raw(string.Format("SearchBar index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> LabelWithIndex(int index)
		{
			return q => q.Raw(string.Format("Label index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> LabelWithText(string text)
		{
			return q => q.Raw(string.Format("Label text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> LabelWithId(string id)
		{
			return q => q.Raw(string.Format("Label id:'{0}'", id));
		}

		public static Func<AppQuery, AppQuery> PickerEntryWithIndex(int index)
		{
			return q => q.Raw(string.Format("TextField index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> PickerEntryWithPlaceholder(string placeholder)
		{
			return q => q.Raw(string.Format("TextField placeholder:'{0}'", placeholder));
		}

		public static Func<AppQuery, AppQuery> PickerEntryWithText(string text)
		{
			return q => q.Raw(string.Format("TextField text:'{0}'", text));
		}

		public static Func<AppQuery, AppQuery> SwitchWithIndex(int index)
		{
			return q => q.Raw(string.Format("Switch index:{0}", index));
		}

		public static Func<AppQuery, AppQuery> StepperWithIndex(int index)
		{
			return q => q.Raw(string.Format("Stepper index:{0}", index));
		}
#endif

	}
}