public T[] Query <T>(Func <AppQuery, AppTypedSelector <T> > query) { var 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 var bindingFlags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic; var selectorType = appTypedSelector.GetType(); var tokensProperty = selectorType.GetProperties(bindingFlags) .First(t => t.PropertyType == typeof(Xamarin.UITest.Queries.Tokens.IQueryToken[])); var tokens = (Xamarin.UITest.Queries.Tokens.IQueryToken[])tokensProperty.GetValue(appTypedSelector); // Output some debugging info //foreach (var t in tokens) //{ // Debug.WriteLine($">>>>> WinDriverApp Query 208: {t.ToQueryString(QueryPlatform.iOS)}"); // Debug.WriteLine($">>>>> WinDriverApp Query 208: {t.ToCodeString()}"); //} var selector = tokens[0].ToQueryString(QueryPlatform.iOS); var invoke = tokens[1].ToCodeString(); // Now that we have them in text form, we can reinterpret them for Windows var winQuery = WinQuery.FromRaw(selector); // TODO hartez 2017/07/19 17:08:44 Make this a bit more resilient if the translation isn't there var attribute = _translatePropertyAccessor[invoke.Substring(8).Replace("\")", "")]; var elements = QueryWindows(winQuery); // TODO hartez 2017/07/19 17:09:14 Alas, for now this simply doesn't work. Waiting for WinAppDrive to implement it return(elements.Select(e => (T)Convert.ChangeType(e.GetAttribute(attribute), typeof(T))).ToArray()); }
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()); }