summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/ScreenshotConditionalApp.cs
blob: cc98b5d1388049d38de365997672e6536600fd21 (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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#if UITEST
using System;
using System.IO;
using Xamarin.UITest;
using Xamarin.UITest.Queries;

namespace Xamarin.Forms.Controls
{
	/// <summary>
	/// Decorator for IApp which only takes screenshots if the SCREENSHOTS symbol  is specified
	/// </summary>
	internal class ScreenshotConditionalApp : IApp
	{
		readonly IApp _app;

		public ScreenshotConditionalApp(IApp app)
		{
			_app = app;
		}

		public AppResult[] Query(Func<AppQuery, AppQuery> query = null)
		{
			return _app.Query(query);
		}

		public AppResult[] Query(string marked)
		{
			return _app.Query(marked);
		}

		public AppWebResult[] Query(Func<AppQuery, AppWebQuery> query)
		{
			return _app.Query(query);
		}

		public T[] Query<T>(Func<AppQuery, AppTypedSelector<T>> query)
		{
			return _app.Query(query);
		}

		public string[] Query(Func<AppQuery, InvokeJSAppQuery> query)
		{
			return _app.Query(query);
		}

		public AppResult[] Flash(Func<AppQuery, AppQuery> query = null)
		{
			return _app.Flash(query);
		}

		public AppResult[] Flash(string marked)
		{
			return _app.Flash(marked);
		}

		public void EnterText(string text)
		{
			_app.EnterText(text);
		}

		public void EnterText(Func<AppQuery, AppQuery> query, string text)
		{
			_app.EnterText(query, text);
		}

		public void EnterText(string marked, string text)
		{
			_app.EnterText(marked, text);
		}

		public void EnterText(Func<AppQuery, AppWebQuery> query, string text)
		{
			_app.EnterText(query, text);
		}

		public void ClearText(Func<AppQuery, AppQuery> query)
		{
			_app.ClearText(query);
		}

		public void ClearText(string marked)
		{
			_app.ClearText(marked);
		}

		public void ClearText()
		{
			_app.ClearText();
		}

		public void PressEnter()
		{
			_app.PressEnter();
		}

		public void DismissKeyboard()
		{
			_app.DismissKeyboard();
		}

		public void Tap(Func<AppQuery, AppQuery> query)
		{
			_app.Tap(query);
		}

		public void Tap(string marked)
		{
			_app.Tap(marked);
		}

		public void Tap(Func<AppQuery, AppWebQuery> query)
		{
			_app.Tap(query);
		}

		public void TapCoordinates(float x, float y)
		{
			_app.TapCoordinates(x, y);
		}

		public void TouchAndHold(Func<AppQuery, AppQuery> query)
		{
			_app.TouchAndHold(query);
		}

		public void TouchAndHold(string marked)
		{
			_app.TouchAndHold(marked);
		}

		public void TouchAndHoldCoordinates(float x, float y)
		{
			_app.TouchAndHoldCoordinates(x, y);
		}

		public void DoubleTap(Func<AppQuery, AppQuery> query)
		{
			_app.DoubleTap(query);
		}

		public void DoubleTap(string marked)
		{
			_app.DoubleTap(marked);
		}

		public void DoubleTapCoordinates(float x, float y)
		{
			_app.DoubleTapCoordinates(x, y);
		}

		public void PinchToZoomIn(Func<AppQuery, AppQuery> query, TimeSpan? duration = null)
		{
			_app.PinchToZoomIn(query, duration);
		}

		public void PinchToZoomIn(string marked, TimeSpan? duration = null)
		{
			_app.PinchToZoomIn(marked, duration);
		}

		public void PinchToZoomInCoordinates(float x, float y, TimeSpan? duration)
		{
			_app.PinchToZoomInCoordinates(x, y, duration);
		}

		public void PinchToZoomOut(Func<AppQuery, AppQuery> query, TimeSpan? duration = null)
		{
			_app.PinchToZoomOut(query, duration);
		}

		public void PinchToZoomOut(string marked, TimeSpan? duration = null)
		{
			_app.PinchToZoomOut(marked, duration);
		}

		public void PinchToZoomOutCoordinates(float x, float y, TimeSpan? duration)
		{
			_app.PinchToZoomOutCoordinates(x, y, duration);
		}

		public void WaitFor(Func<bool> predicate, string timeoutMessage = "Timed out waiting...", TimeSpan? timeout = null,
			TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null)
		{
			_app.WaitFor(predicate, timeoutMessage, timeout, retryFrequency, postTimeout);
		}

		public AppResult[] WaitForElement(Func<AppQuery, AppQuery> query, string timeoutMessage = "Timed out waiting for element...",
			TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null)
		{
			return _app.WaitForElement(query, timeoutMessage, timeout, retryFrequency, postTimeout);
		}

		public AppResult[] WaitForElement(string marked, string timeoutMessage = "Timed out waiting for element...",
			TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null)
		{
			return _app.WaitForElement(marked, timeoutMessage, timeout, retryFrequency, postTimeout);
		}

		public AppWebResult[] WaitForElement(Func<AppQuery, AppWebQuery> query, string timeoutMessage = "Timed out waiting for element...",
			TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null)
		{
			return _app.WaitForElement(query, timeoutMessage, timeout, retryFrequency, postTimeout);
		}

		public void WaitForNoElement(Func<AppQuery, AppQuery> query, string timeoutMessage = "Timed out waiting for no element...",
			TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null)
		{
			_app.WaitForNoElement(query, timeoutMessage, timeout, retryFrequency, postTimeout);
		}

		public void WaitForNoElement(string marked, string timeoutMessage = "Timed out waiting for no element...",
			TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null)
		{
			_app.WaitForNoElement(marked, timeoutMessage, timeout, retryFrequency, postTimeout);
		}

		public void WaitForNoElement(Func<AppQuery, AppWebQuery> query, string timeoutMessage = "Timed out waiting for no element...",
			TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null)
		{
			_app.WaitForNoElement(query, timeoutMessage, timeout, retryFrequency, postTimeout);
		}

		public FileInfo Screenshot(string title)
		{
#if SCREENSHOTS
			return _app.Screenshot(title);
#else
			return null;
#endif
		}

		public void SwipeRight()
		{
#pragma warning disable 618
			_app.SwipeRight();
#pragma warning restore 618
		}

		public void SwipeLeftToRight(double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true)
		{
			_app.SwipeLeftToRight(swipePercentage, swipeSpeed, withInertia);
		}

		public void SwipeLeftToRight(string marked, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true)
		{
			_app.SwipeLeftToRight(marked, swipePercentage, swipeSpeed, withInertia);
		}

		public void SwipeLeft()
		{
#pragma warning disable 618
			_app.SwipeLeft();
#pragma warning restore 618
		}

		public void SwipeRightToLeft(double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true)
		{
			_app.SwipeRightToLeft(swipePercentage, swipeSpeed, withInertia);
		}

		public void SwipeRightToLeft(string marked, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true)
		{
			_app.SwipeRightToLeft(marked, swipePercentage, swipeSpeed, withInertia);
		}

		public void SwipeLeftToRight(Func<AppQuery, AppQuery> query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true)
		{
			_app.SwipeLeftToRight(query, swipePercentage, swipeSpeed, withInertia);
		}

		public void SwipeRightToLeft(Func<AppQuery, AppQuery> query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true)
		{
			_app.SwipeRightToLeft(query, swipePercentage, swipeSpeed, withInertia);
		}

		public void ScrollUp(Func<AppQuery, AppQuery> query = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500,
			bool withInertia = true)
		{
			_app.ScrollUp(query, strategy, swipePercentage, swipeSpeed, withInertia);
		}

		public void ScrollUp(string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500,
			bool withInertia = true)
		{
			_app.ScrollUp(withinMarked, strategy, swipePercentage, swipeSpeed, withInertia);
		}

		public void ScrollDown(Func<AppQuery, AppQuery> withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true)
		{
			_app.ScrollDown(withinQuery, strategy, swipePercentage, swipeSpeed, withInertia);
		}

		public void ScrollDown(string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500,
			bool withInertia = true)
		{
			_app.ScrollDown(withinMarked, strategy, swipePercentage, swipeSpeed, withInertia);
		}

		public void ScrollTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollTo(toMarked, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollUpTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto,
			double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollUpTo(toMarked, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollUpTo(Func<AppQuery, AppWebQuery> toQuery, string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollUpTo(toQuery, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollDownTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto,
			double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollDownTo(toMarked, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollDownTo(Func<AppQuery, AppWebQuery> toQuery, string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollDownTo(toQuery, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollUpTo(Func<AppQuery, AppQuery> toQuery, Func<AppQuery, AppQuery> withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollUpTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollUpTo(Func<AppQuery, AppWebQuery> toQuery, Func<AppQuery, AppQuery> withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollUpTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollDownTo(Func<AppQuery, AppQuery> toQuery, Func<AppQuery, AppQuery> withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollDownTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void ScrollDownTo(Func<AppQuery, AppWebQuery> toQuery, Func<AppQuery, AppQuery> withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67,
			int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null)
		{
			_app.ScrollDownTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout);
		}

		public void SetOrientationPortrait()
		{
			_app.SetOrientationPortrait();
		}

		public void SetOrientationLandscape()
		{
			_app.SetOrientationLandscape();
		}

		public void Repl()
		{
			_app.Repl();
		}

		public void Back()
		{
			_app.Back();
		}

		public void PressVolumeUp()
		{
			_app.PressVolumeUp();
		}

		public void PressVolumeDown()
		{
			_app.PressVolumeDown();
		}

		public object Invoke(string methodName, object argument = null)
		{
			return _app.Invoke(methodName, argument);
		}

		public object Invoke(string methodName, object[] arguments)
		{
			return _app.Invoke(methodName, arguments);
		}

		public void DragCoordinates(float fromX, float fromY, float toX, float toY)
		{
			_app.DragCoordinates(fromX, fromY, toX, toY);
		}

		public void DragAndDrop(Func<AppQuery, AppQuery> @from, Func<AppQuery, AppQuery> to)
		{
			_app.DragAndDrop(@from, to);
		}

		public void DragAndDrop(string @from, string to)
		{
			_app.DragAndDrop(@from, to);
		}

		public void SetSliderValue(string marked, double value)
		{
			_app.SetSliderValue(marked, value);
		}

		public void SetSliderValue(Func<AppQuery, AppQuery> query, double value)
		{
			_app.SetSliderValue(query, value);
		}

		public AppPrintHelper Print
		{
			get { return _app.Print; }
		}

		public IDevice Device
		{
			get { return _app.Device; }
		}

		public ITestServer TestServer
		{
			get { return _app.TestServer; }
		}
	}
}
#endif