/
WinQuery.cs
67 lines (52 loc) · 1.58 KB
/
WinQuery.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
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Xamarin.UITest.Queries;
namespace Xamarin.Forms.Core.UITests
{
internal class WinQuery
{
public static WinQuery FromQuery(Func<AppQuery, AppQuery> query)
{
var raw = GetRawQuery(query);
return FromRaw(raw);
}
public static WinQuery FromMarked(string marked)
{
return new WinQuery("*", marked, $"* '{marked}'");
}
public static WinQuery FromRaw(string raw)
{
Debug.WriteLine($">>>>> Converting raw query '{raw}' to {nameof(WinQuery)}");
var match = Regex.Match(raw, @"(.*)\s(marked|text):'((.|\n)*)'");
var controlType = match.Groups[1].Captures[0].Value;
var marked = match.Groups[3].Captures[0].Value;
// Just ignoring everything else for now (parent, index statements, etc)
var result = new WinQuery(controlType, marked, raw);
Debug.WriteLine($">>>>> WinQuery is: {result}");
return result;
}
static string GetRawQuery(Func<AppQuery, AppQuery> query = null)
{
if (query == null)
{
return string.Empty;
}
// When we pull out the iOS query it's got any instances of "'" escaped with "\", need to fix that up
return query(new AppQuery(QueryPlatform.iOS)).ToString().Replace("\\'", "'");
}
WinQuery(string controlType, string marked, string raw)
{
ControlType = controlType;
Marked = marked;
Raw = raw;
}
public string ControlType { get; }
public string Marked { get; }
public string Raw { get; }
public override string ToString()
{
return $"{nameof(ControlType)}: {ControlType}, {nameof(Marked)}: {Marked}";
}
}
}