Example #1
0
 public void DragAndDrop(string from, string to)
 {
     DragAndDrop(
         FindFirstElement(WinQuery.FromMarked(from)),
         FindFirstElement(WinQuery.FromMarked(to))
         );
 }
Example #2
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));
        }
Example #3
0
 public void DragAndDrop(Func <AppQuery, AppQuery> from, Func <AppQuery, AppQuery> to)
 {
     DragAndDrop(
         FindFirstElement(WinQuery.FromQuery(from)),
         FindFirstElement(WinQuery.FromQuery(to))
         );
 }
Example #4
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);
 }
Example #5
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);
        }
Example #6
0
        void Tap(WinQuery query)
        {
            WindowsElement element = FindFirstElement(query);

            if (element == null)
            {
                return;
            }

            ClickOrTapElement(element);
        }
Example #7
0
        void DoubleTap(WinQuery query)
        {
            WindowsElement element = FindFirstElement(query);

            if (element == null)
            {
                return;
            }

            DoubleClickElement(element);
        }
Example #8
0
        void Scroll(WinQuery query, bool down)
        {
            if (query == null)
            {
                ScrollClick(GetWindow(), down);
                return;
            }

            WindowsElement element = FindFirstElement(query);

            ScrollClick(element, down);
        }
Example #9
0
        WindowsElement FindFirstElement(WinQuery query)
        {
            Func <ReadOnlyCollection <WindowsElement> > fquery =
                () => QueryWindows(query, true);

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

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

            WindowsElement element = results.FirstOrDefault();

            return(element);
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
0
        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
            var translationKey = invoke.Substring(8).Replace("\")", "");

            if (!_translatePropertyAccessor.ContainsKey(translationKey))
            {
                throw new Exception($"{translationKey} not found please add to _translatePropertyAccessor");
            }

            string attribute = _translatePropertyAccessor[translationKey];

            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());
        }
Example #13
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);
            }
        }
Example #14
0
        public AppResult[] Query(Func <AppQuery, AppQuery> query = null)
        {
            ReadOnlyCollection <WindowsElement> elements = QueryWindows(WinQuery.FromQuery(query));

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

            return(QueryWindows(winQuery, findFirst));
        }
Example #16
0
        public void Tap(string marked)
        {
            WinQuery winQuery = WinQuery.FromMarked(marked);

            Tap(winQuery);
        }
Example #17
0
        public void Tap(Func <AppQuery, AppQuery> query)
        {
            WinQuery winQuery = WinQuery.FromQuery(query);

            Tap(winQuery);
        }
Example #18
0
 public void DoubleTap(Func <AppQuery, AppQuery> query)
 {
     DoubleTap(WinQuery.FromQuery(query));
 }
Example #19
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);
 }
Example #20
0
 public void DoubleTap(string marked)
 {
     DoubleTap(WinQuery.FromMarked(marked));
 }
Example #21
0
        ReadOnlyCollection <WindowsElement> QueryWindows(string marked, bool findFirst = false)
        {
            WinQuery winQuery = WinQuery.FromMarked(marked);

            return(QueryWindows(winQuery, findFirst));
        }