summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.macOS.UITests/MacOSApp.cs
blob: 08c3118dca7766c11b1b189653a81bda254f12ad (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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
using System;
using System.IO;
using System.Collections.Generic;
using Xamarin.UITest;
using Xamarin.UITest.Desktop;
using Xamarin.UITest.Queries;
using System.Linq;
using System.Diagnostics;
using System.Threading;
using System.Drawing;

namespace Xamarin.Forms.Core.macOS.UITests
{
	public static class MacOSAppExtensions
	{
		public static UITest.Queries.AppResult ToUITestResult(this UITest.Desktop.AppResult result)
		{
			return new UITest.Queries.AppResult
			{
				Id = result.Id ?? result.TestId,
				Label = result.Label,
				Text = result.Text ?? result.Value,
				Enabled = result.Enabled,
				Class = result.Class,
				Rect = new UITest.Queries.AppRect
				{
					X = result.Rect.X,
					Y = result.Rect.Y,
					Width = result.Rect.Width,
					Height = result.Rect.Height,
					CenterX = result.Rect.CenterX,
					CenterY = result.Rect.CenterY
				}
			};
		}
	}


	public class MacOSApp : Xamarin.UITest.IApp
	{
		string _backButtonIdentifier = "NSBackButton";
		static CocoaApp _cocoaApp;
		public MacOSApp(CocoaApp app)
		{
			_cocoaApp = app;
		}
		public IDevice Device
		{
			get
			{
				return null;
			}
		}

		public AppPrintHelper Print
		{
			get
			{
				return null;
			}
		}

		public ITestServer TestServer
		{
			get
			{
				return null;
			}
		}

		public void Back()
		{
			Tap(_backButtonIdentifier);
		}

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

		public void ClearText(string marked)
		{
			var textField = _cocoaApp.QueryById(marked).FirstOrDefault((arg) => arg.Class.Contains("SearchField") || arg.Class.Contains("TextField"));
			ClearText(textField.Rect.CenterX, textField.Rect.CenterY);
		}

		public void ClearText(Func<AppQuery, AppWebQuery> query)
		{

		}

		public void ClearText(Func<AppQuery, AppQuery> query)
		{
			var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString();

			var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b");
			if (isMarked)
			{
				var markedWord = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'");
				var isAll = markedWord[0].Trim() == "*";
				var marked = markedWord[1].Replace("'", "");
				ClearText(marked);
			}
		}

		public void DismissKeyboard()
		{

		}

		public void DoubleTap(string marked)
		{

		}

		public void DoubleTap(Func<AppQuery, AppQuery> query)
		{

		}

		public void DoubleTapCoordinates(float x, float y)
		{

		}

		public void DragAndDrop(string from, string to)
		{

		}

		public void DragAndDrop(Func<AppQuery, AppQuery> from, Func<AppQuery, AppQuery> to)
		{

		}

		public void DragCoordinates(float fromX, float fromY, float toX, float toY)
		{

		}

		public void EnterText(string text)
		{
			var all = _cocoaApp.Query();
			var staticText = _cocoaApp.QueryByType("StaticText");
			var textFields = _cocoaApp.QueryByType("Textfield");
			var textField = staticText.Union(textFields).FirstOrDefault();
			EnterText(text, textField.Rect.CenterX, textField.Rect.CenterY);
		}

		public void EnterText(Func<AppQuery, AppWebQuery> query, string text)
		{

		}

		public void EnterText(string marked, string text)
		{
			var textField = _cocoaApp.QueryById(marked).FirstOrDefault((arg) => arg.Class.Contains("SearchField") || arg.Class.Contains("TextField"));
			EnterText(text, textField.Rect.CenterX, textField.Rect.CenterY);
		}

		public void EnterText(Func<AppQuery, AppQuery> query, string text)
		{
			string markedWord = string.Empty;
			int indexMarked = 0;

			if (ExtractInfo(query, out markedWord, out indexMarked))
				EnterText(markedWord, indexMarked, text);
		}

		public UITest.Queries.AppResult[] Flash(string marked)
		{
			var resulr = new List<Xamarin.UITest.Queries.AppResult>();
			return resulr.ToArray();
		}

		public UITest.Queries.AppResult[] Flash(Func<AppQuery, AppQuery> query = null)
		{
			var resulr = new List<Xamarin.UITest.Queries.AppResult>();
			return resulr.ToArray();
		}

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

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

		public void PinchToZoomIn(string marked, TimeSpan? duration = default(TimeSpan?))
		{

		}

		public void PinchToZoomIn(Func<AppQuery, AppQuery> query, TimeSpan? duration = default(TimeSpan?))
		{

		}

		public void PinchToZoomInCoordinates(float x, float y, TimeSpan? duration)
		{

		}

		public void PinchToZoomOut(string marked, TimeSpan? duration = default(TimeSpan?))
		{

		}

		public void PinchToZoomOut(Func<AppQuery, AppQuery> query, TimeSpan? duration = default(TimeSpan?))
		{

		}

		public void PinchToZoomOutCoordinates(float x, float y, TimeSpan? duration)
		{

		}

		public void PressEnter()
		{
			_cocoaApp.SendKey(13, KeyModifier.None);
		}

		public void PressVolumeDown()
		{

		}

		public void PressVolumeUp()
		{

		}

		public AppWebResult[] Query(Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppWebQuery> query)
		{
			var resulr = new List<Xamarin.UITest.Queries.AppWebResult>();
			return resulr.ToArray();
		}

		public string[] Query(Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.InvokeJSAppQuery> query)
		{
			return new List<string>().ToArray();
		}

		public UITest.Queries.AppResult[] Query(string marked)
		{
			var results = new List<Xamarin.UITest.Queries.AppResult>();
			var allResults = _cocoaApp.Query();
			var allResultsById = _cocoaApp.QueryById(marked);
			foreach (var result in allResultsById)
				results.Add(result.ToUITestResult());
			var allResultsByText = _cocoaApp.QueryByText(marked);
			foreach (var result in allResultsByText)
				results.Add(result.ToUITestResult());
			return results.ToArray();
		}

		public UITest.Queries.AppResult[] Query(Func<UITest.Queries.AppQuery, UITest.Queries.AppQuery> query = null)
		{
			var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString();
			var results = new List<Xamarin.UITest.Queries.AppResult>();
			var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b");
			var isText = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\btext\b");
			if (isMarked)
			{
				var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'");
				var isAll = markedWords[0].Trim() == "*";
				var markedWord = markedWords[1].Remove(markedWords[1].Length - 1).Trim();
				return Query(markedWord);
			}
			if (isText)
			{
				var textWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\btext\b:'");
				var isAll = textWords[0].Trim() == "*";
				var textWord = textWords[1].Remove(textWords[1].Length - 1).Trim();
				return Query(textWord);
			}
			else if (queryStr.Contains("* index:0"))
			{
				var allREsults = _cocoaApp.Query();
				var result = allREsults[0].Children[0];
				results.Add(result.ToUITestResult());
			}
			else if (queryStr.Contains("* index:7"))
			{
				var allREsults = _cocoaApp.Query();
				var result = allREsults[0].Children[0].Children[0].Children[1];
				results.Add(result.ToUITestResult());
			}

			return results.ToArray();
		}

		public T[] Query<T>(Func<UITest.Queries.AppQuery, UITest.Queries.AppTypedSelector<T>> query)
		{

			var results = new List<T>();
			var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString();
			var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b");
			if (isMarked)
			{
				var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'");
				var isAll = markedWords[0].Trim() == "*";
				var markedWord = markedWords[1].Replace("'", "");
				var ss = Query(markedWord);

			}
			else if (queryStr.Contains("* index:0"))
			{

				var allREsults = _cocoaApp.Query();
				var result = allREsults[0].Children[0];
				//	results.Add(result.ToUITestResult());
			}
			else if (queryStr.Contains("* index:7"))
			{
				var allREsults = _cocoaApp.Query();
				var result = allREsults[0].Children[0].Children[0].Children[1];
				//	results.Add(result.ToUITestResult());
			}

			return results.ToArray();
		}

		public void Repl()
		{

		}

		public FileInfo Screenshot(string title)
		{
			return null;
		}

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

		}

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

		}

		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 = default(TimeSpan?))
		{

		}

		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 = default(TimeSpan?))
		{

		}

		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 = default(TimeSpan?))
		{

		}

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

		}

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

		}

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

		}

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

		}

		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 = default(TimeSpan?))
		{

		}

		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 = default(TimeSpan?))
		{

		}

		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 = default(TimeSpan?))
		{

		}

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

		}

		public void SetOrientationLandscape()
		{

		}

		public void SetOrientationPortrait()
		{

		}

		public void SetSliderValue(Func<AppQuery, AppQuery> query, double value)
		{

		}

		public void SetSliderValue(string marked, double value)
		{

		}

		public void SwipeLeft()
		{

		}

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

		}

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

		}

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

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

		}

		public void SwipeRight()
		{

		}

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

		}

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

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

		}

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

		}

		public void Tap(Func<AppQuery, AppWebQuery> query)
		{

		}

		public void Tap(string marked)
		{
			Tap(marked, 0);
		}

		public void Tap(Func<AppQuery, AppQuery> query)
		{
			string markedWord = string.Empty;
			int indexMarked = 0;

			if (ExtractInfo(query, out markedWord, out indexMarked))
				Tap(markedWord, indexMarked);
		}

		public void TapCoordinates(float x, float y)
		{

		}

		public void TouchAndHold(string marked)
		{
			TouchAndHold(marked, 0);
		}

		void TouchAndHold(string marked, int index)
		{
			var safeIndex = Math.Max(index, 0);
			var queryById = _cocoaApp.QueryById(marked.Trim())[safeIndex];
			TouchAndHoldCoordinates(queryById.Rect.CenterX, queryById.Rect.CenterY);

		}

		public void TouchAndHold(Func<AppQuery, AppQuery> query)
		{
			string markedWord = string.Empty;
			int indexMarked = 0;

			if (ExtractInfo(query, out markedWord, out indexMarked))
				TouchAndHold(markedWord, indexMarked);
		}

		public void TouchAndHoldCoordinates(float x, float y)
		{
			_cocoaApp.RightClick(x, y);
			Thread.Sleep(1000);
		}

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

		}

		public AppWebResult[] WaitForElement(Func<AppQuery, AppWebQuery> query, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?))
		{
			var resulr = new List<Xamarin.UITest.Queries.AppWebResult>();
			return resulr.ToArray();
		}

		public UITest.Queries.AppResult[] WaitForElement(string marked, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?))
		{
			var results = new List<Xamarin.UITest.Queries.AppResult>();

			var queryById = _cocoaApp.QueryById(marked);
			foreach (var res in queryById)
			{
				results.Add(res.ToUITestResult());
			}
			Stopwatch s = new Stopwatch();
			s.Start();
			bool foundElement = false;
			while (s.Elapsed < timeout && !foundElement)
			{
				var allResultsById = _cocoaApp.QueryById(marked);
				foreach (var res in queryById)
				{
					results.Add(res.ToUITestResult());
				}
				foundElement = results.Count > 0;
				System.Diagnostics.Debug.WriteLine(foundElement);
			}
			s.Stop();

			return results.ToArray();
		}

		public UITest.Queries.AppResult[] WaitForElement(Func<AppQuery, AppQuery> query, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?))
		{
			var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString();
			var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b");
			if (isMarked)
			{
				var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'");
				var isAll = markedWords[0].Trim() == "*";
				var markedWord = markedWords[1].Replace("'", "").Trim();
				return WaitForElement(markedWord, timeoutMessage, timeout, retryFrequency, postTimeout);
			}
			return new List<Xamarin.UITest.Queries.AppResult>().ToArray();
		}

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


		}

		public void WaitForNoElement(string marked, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?))
		{
			Stopwatch s = new Stopwatch();
			s.Start();
			bool noElement = false;
			while (s.Elapsed < timeout && !noElement)
			{
				var allResultsById = _cocoaApp.QueryById(marked);
				noElement = allResultsById.Length == 0;
				System.Diagnostics.Debug.WriteLine(noElement);
			}
			s.Stop();
			if (s.Elapsed < timeout && !noElement)
				throw (new Exception(timeoutMessage));

		}

		public void WaitForNoElement(Func<AppQuery, AppQuery> query, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = default(TimeSpan?), TimeSpan? retryFrequency = default(TimeSpan?), TimeSpan? postTimeout = default(TimeSpan?))
		{
			var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString();
			var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b");
			if (isMarked)
			{
				var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'");
				var isAll = markedWords[0].Trim() == "*";
				var markedWord = markedWords[1].Replace("'", "").Trim();
				WaitForNoElement(markedWord, timeoutMessage, timeout, retryFrequency, postTimeout);
			}
		}

		static bool ExtractInfo(Func<AppQuery, AppQuery> query, out string markedWord, out int indexMarked)
		{
			indexMarked = 0;
			markedWord = string.Empty;
			var isSuccess = false;
			var queryStr = query(new AppQuery(QueryPlatform.iOS)).ToString();
			var isIndex = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bindex\b");
			if (isIndex)
			{
				var indexWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bindex\b:");
				var indexWord = indexWords[1];
				int.TryParse(indexWord, out indexMarked);
				queryStr = indexWords[0].Trim();
			}
			var isMarked = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\bmarked\b");
			if (isMarked)
			{
				var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\bmarked\b:'");
				var isAll = markedWords[0].Trim() == "*";
				markedWord = markedWords[1].Replace("'", "").Trim();
				isSuccess = true;

			}
			var isText = System.Text.RegularExpressions.Regex.IsMatch(queryStr, @"\btext\b");
			if (isText)
			{
				var markedWords = System.Text.RegularExpressions.Regex.Split(queryStr, @"\btext\b:'");
				var isAll = markedWords[0].Trim() == "*";
				markedWord = markedWords[1].Replace("'", "").Trim();
				isSuccess = true;
			}
			return isSuccess;
		}

		void Tap(string marked, int index)
		{
			var safeIndex = Math.Max(index, 0);
			var queryById = _cocoaApp.QueryById(marked.Trim())[safeIndex];
			_cocoaApp.Click(queryById.Rect.CenterX, queryById.Rect.CenterY);
			Thread.Sleep(1000);
		}

		static void EnterText(string marked, int index, string text)
		{
			UITest.Desktop.AppResult textField = null;
			var safeIndex = Math.Max(index, 0);
			var textFields = _cocoaApp.QueryById(marked).Where((arg) => arg.Class.Contains("SearchField") || arg.Class.Contains("TextField"));
			if (textFields.Count() > 0)
			{
				textField = textFields.ElementAt(safeIndex);
			}
			else
			{
				var markedField = _cocoaApp.QueryById(marked);
				if (markedField.Length > 0)
				{
					textField = markedField[0];
				}
				else
				{

					var allTextFields = _cocoaApp.QueryByType("TextField");
					textField = allTextFields[0];
				}
			}

			if (textField != null)
				EnterText(text, textField.Rect.CenterX, textField.Rect.CenterY);

		}

		static void EnterText(string text, float x, float y)
		{
			_cocoaApp.Click(x, y);
			_cocoaApp.Click(x, y);
			Thread.Sleep(500);
			_cocoaApp.EnterText(text);
			Thread.Sleep(500);
		}

		static void ClearText(float x, float y)
		{
			_cocoaApp.Click(x, y);
			_cocoaApp.Click(x, y);
			Thread.Sleep(500);
			_cocoaApp.ClearText();
			Thread.Sleep(500);
		}
	}
}