public T[] Query <T>(Func <AppQuery, AppTypedSelector <T> > query) { AppTypedSelector <T> appTypedSelector = query(new AppQuery(QueryPlatform.iOS)); // Swiss-Army Chainsaw time // We'll use reflection to dig into the query and get the element selector // and the property value invocation in text form BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic; Type selectorType = appTypedSelector.GetType(); PropertyInfo tokensProperty = selectorType.GetProperties(bindingFlags) .First(t => t.PropertyType == typeof(IQueryToken[])); var tokens = (IQueryToken[])tokensProperty.GetValue(appTypedSelector); string selector = tokens[0].ToQueryString(QueryPlatform.iOS); string invoke = tokens[1].ToCodeString(); // Now that we have them in text form, we can reinterpret them for Windows WinQuery winQuery = WinQuery.FromRaw(selector); // TODO hartez 2017/07/19 17:08:44 Make this a bit more resilient if the translation isn't there string attribute = _translatePropertyAccessor[invoke.Substring(8).Replace("\")", "")]; ReadOnlyCollection <WindowsElement> elements = QueryWindows(winQuery); foreach (WindowsElement e in elements) { string x = e.GetAttribute(attribute); Debug.WriteLine($">>>>> WinDriverApp Query 261: {x}"); } // TODO hartez 2017/07/19 17:09:14 Alas, for now this simply doesn't work. Waiting for WinAppDriver to implement it return(elements.Select(e => (T)Convert.ChangeType(e.GetAttribute(attribute), typeof(T))).ToArray()); }
public static IAppTypedSelector <T> AsGenericAppTypedSelector <T>(this AppTypedSelector <object> selector) => new XamarinAppTypedSelector <T>(selector);
public static IAppTypedSelector <string> AsGenericAppTypedSelector(this AppTypedSelector <string> selector) => new XamarinAppTypedSelector <string>(selector.Value <object>());
public XamarinAppTypedSelector(AppTypedSelector <object> selector) => _source = selector;