示例#1
0
 public void DragAndDrop(string from, string to)
 {
     DragAndDrop(
         FindFirstElement(WinQuery.FromMarked(from)),
         FindFirstElement(WinQuery.FromMarked(to))
         );
 }
示例#2
0
 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)
 {
     ScrollTo(WinQuery.FromQuery(toQuery), withinQuery == null ? null : WinQuery.FromQuery(withinQuery), timeout,
              down: false);
 }
示例#3
0
 public void DragAndDrop(Func <AppQuery, AppQuery> from, Func <AppQuery, AppQuery> to)
 {
     DragAndDrop(
         FindFirstElement(WinQuery.FromQuery(from)),
         FindFirstElement(WinQuery.FromQuery(to))
         );
 }
示例#4
0
        ReadOnlyCollection <WindowsElement> QueryWindows(WinQuery query, bool findFirst = false)
        {
            var resultByAccessibilityId = _session.FindElementsByAccessibilityId(query.Marked);
            ReadOnlyCollection <WindowsElement> resultByName = null;

            if (!findFirst || resultByAccessibilityId.Count == 0)
            {
                resultByName = _session.FindElementsByName(query.Marked);
            }

            IEnumerable <WindowsElement> result = resultByAccessibilityId;

            if (resultByName != null)
            {
                result = result.Concat(resultByName);
            }

            // TODO hartez 2017/10/30 09:47:44 Should this be == "*" || == "TextBox"?
            // what about other controls where we might be looking by content? TextBlock?
            if (query.ControlType == "*")
            {
                IEnumerable <WindowsElement> textBoxesByContent =
                    _session.FindElementsByClassName("TextBox").Where(e => e.Text == query.Marked);
                result = result.Concat(textBoxesByContent);
            }

            return(FilterControlType(result, query.ControlType));
        }
示例#5
0
        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());
        }
示例#7
0
        public void ScrollUp(string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto,
                             double swipePercentage = 0.67, int swipeSpeed = 500,
                             bool withInertia       = true)
        {
            WinQuery winQuery = WinQuery.FromMarked(withinMarked);

            Scroll(winQuery, false);
        }
示例#8
0
        void Tap(WinQuery query)
        {
            WindowsElement element = FindFirstElement(query);

            if (element == null)
            {
                return;
            }

            ClickOrTapElement(element);
        }
示例#9
0
        void DoubleTap(WinQuery query)
        {
            WindowsElement element = FindFirstElement(query);

            if (element == null)
            {
                return;
            }

            DoubleClickElement(element);
        }
示例#10
0
        WindowsElement FindFirstElement(WinQuery query)
        {
            Func <ReadOnlyCollection <WindowsElement> > fquery = () => QueryWindows(query);

            string timeoutMessage = $"Timed out waiting for element: {query.Raw}";

            ReadOnlyCollection <WindowsElement> results = WaitForAtLeastOne(fquery, timeoutMessage);

            WindowsElement element = results.FirstOrDefault();

            return(element);
        }
示例#11
0
        void Scroll(WinQuery query, bool down)
        {
            if (query == null)
            {
                ScrollClick(GetWindow(), down);
                return;
            }

            WindowsElement element = FindFirstElement(query);

            ScrollClick(element, down);
        }
示例#12
0
        public void ScrollUp(Func <AppQuery, AppQuery> query = null, ScrollStrategy strategy = ScrollStrategy.Auto,
                             double swipePercentage          = 0.67, int swipeSpeed = 500,
                             bool withInertia = true)
        {
            if (query == null)
            {
                Scroll(null, false);
                return;
            }

            WinQuery winQuery = WinQuery.FromQuery(query);

            Scroll(winQuery, false);
        }
示例#13
0
        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);
        }
示例#14
0
        ReadOnlyCollection <WindowsElement> QueryWindows(WinQuery query)
        {
            var resultByName            = _session.FindElementsByName(query.Marked);
            var resultByAccessibilityId = _session.FindElementsByAccessibilityId(query.Marked);

            var result = resultByName
                         .Concat(resultByAccessibilityId);

            if (query.ControlType == "*")
            {
                var textBoxesByContent = _session.FindElementsByClassName("TextBox").Where(e => e.Text == query.Marked);
                result = result.Concat(textBoxesByContent);
            }

            return(FilterControlType(result, query.ControlType));
        }
示例#15
0
        void Tap(WinQuery query, int taps = 1)
        {
            Func <ReadOnlyCollection <WindowsElement> > fquery = () => QueryWindows(query);

            var timeoutMessage = $"Timed out waiting for element: {query.Raw}";

            var results = WaitForAtLeastOne(fquery, timeoutMessage);

            if (results.Any())
            {
                var element = results.First();

                for (int n = 0; n < taps; n++)
                {
                    element.Click();
                }
            }
        }
示例#16
0
        void ScrollTo(WinQuery toQuery, WinQuery withinQuery, TimeSpan?timeout = null, bool down = true)
        {
            timeout = timeout ?? DefaultTimeout;
            DateTime start = DateTime.Now;

            while (true)
            {
                Func <ReadOnlyCollection <WindowsElement> > result = () => QueryWindows(toQuery);
                TimeSpan iterationTimeout = TimeSpan.FromMilliseconds(0);
                TimeSpan retryFrequency   = TimeSpan.FromMilliseconds(0);

                try
                {
                    ReadOnlyCollection <WindowsElement> found = WaitForAtLeastOne(result, timeoutMessage: null,
                                                                                  timeout: iterationTimeout, retryFrequency: retryFrequency);

                    if (found.Count > 0)
                    {
                        // Success
                        return;
                    }
                }
                catch (TimeoutException ex)
                {
                    // Haven't found it yet, keep scrolling
                }

                long elapsed = DateTime.Now.Subtract(start).Ticks;
                if (elapsed >= timeout.Value.Ticks)
                {
                    Debug.WriteLine($">>>>> {elapsed} ticks elapsed, timeout value is {timeout.Value.Ticks}");
                    throw new TimeoutException($"Timed out scrolling to {toQuery}");
                }

                Scroll(withinQuery, down);
            }
        }
示例#17
0
        public void DoubleTap(string marked)
        {
            var winQuery = WinQuery.FromMarked(marked);

            Tap(winQuery, 2);
        }
示例#18
0
        public void DoubleTap(Func <AppQuery, AppQuery> query)
        {
            var winQuery = WinQuery.FromQuery(query);

            Tap(winQuery, 2);
        }
示例#19
0
        public void Tap(string marked)
        {
            var winQuery = WinQuery.FromMarked(marked);

            Tap(winQuery);
        }
示例#20
0
        public AppResult[] Query(Func <AppQuery, AppQuery> query = null)
        {
            var elements = QueryWindows(WinQuery.FromQuery(query));

            return(elements.Select(ToAppResult).ToArray());
        }
示例#21
0
        ReadOnlyCollection <WindowsElement> QueryWindows(Func <AppQuery, AppQuery> query)
        {
            var winQuery = WinQuery.FromQuery(query);

            return(QueryWindows(winQuery));
        }
示例#22
0
        ReadOnlyCollection <WindowsElement> QueryWindows(string marked)
        {
            var winQuery = WinQuery.FromMarked(marked);

            return(QueryWindows(winQuery));
        }
示例#23
0
 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)
 {
     ScrollTo(WinQuery.FromMarked(toMarked), withinMarked == null ? null : WinQuery.FromMarked(withinMarked), timeout,
              down: false);
 }
示例#24
0
        public AppResult[] Query(Func <AppQuery, AppQuery> query = null)
        {
            ReadOnlyCollection <WindowsElement> elements = QueryWindows(WinQuery.FromQuery(query));

            return(elements.Select(ToAppResult).ToArray());
        }
示例#25
0
        ReadOnlyCollection <WindowsElement> QueryWindows(Func <AppQuery, AppQuery> query, bool findFirst = false)
        {
            WinQuery winQuery = WinQuery.FromQuery(query);

            return(QueryWindows(winQuery, findFirst));
        }
示例#26
0
        ReadOnlyCollection <WindowsElement> QueryWindows(string marked, bool findFirst = false)
        {
            WinQuery winQuery = WinQuery.FromMarked(marked);

            return(QueryWindows(winQuery, findFirst));
        }
示例#27
0
 public void DoubleTap(Func <AppQuery, AppQuery> query)
 {
     DoubleTap(WinQuery.FromQuery(query));
 }
示例#28
0
 public void DoubleTap(string marked)
 {
     DoubleTap(WinQuery.FromMarked(marked));
 }
示例#29
0
        public void Tap(Func <AppQuery, AppQuery> query)
        {
            WinQuery winQuery = WinQuery.FromQuery(query);

            Tap(winQuery);
        }