Ejemplo n.º 1
1
        internal static CruciatusElement FindFirst(CruciatusElement parent, By getStrategy, int timeout)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            var element = FindFirst(parent.Instance, getStrategy, timeout);
            return element == null ? null : new CruciatusElement(parent, element, getStrategy);
        }
Ejemplo n.º 2
0
        internal static bool TryClickOnBoundingRectangleCenter(
            MouseButton button, 
            CruciatusElement element, 
            bool doubleClick)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            Point point;
            if (!AutomationElementHelper.TryGetBoundingRectangleCenter(element.Instance, out point))
            {
                Logger.Debug("Element '{0}' have empty BoundingRectangle", element);
                return false;
            }

            if (doubleClick)
            {
                CruciatusFactory.Mouse.DoubleClick(button, point.X, point.Y);
            }
            else
            {
                CruciatusFactory.Mouse.Click(button, point.X, point.Y);
            }

            Logger.Info(
                "{0} on '{1}' element at ({2}, {3}) BoundingRectangle center", 
                doubleClick ? "DoubleClick" : "Click", 
                element, 
                point.X, 
                point.Y);
            return true;
        }
Ejemplo n.º 3
0
        internal static IEnumerable<CruciatusElement> FindAll(CruciatusElement parent, By strategy, int timeout)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            var result = strategy.FindAll(parent.Instance, timeout);
            return result.Select(e => new CruciatusElement(parent, e, strategy));
        }
Ejemplo n.º 4
0
        internal static CruciatusElement FindFirst(CruciatusElement parent, By strategy, int timeout)
        {
            var element = strategy.FindFirst(parent.Instance, timeout);
            if (element == null)
            {
                Logger.Info("Element '{0}' not found", strategy);
                CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
                return null;
            }

            return new CruciatusElement(parent, element, strategy);
        }
        public string RegisterElement(CruciatusElement element)
        {
            var registeredKey =
                this.registeredElements.FirstOrDefault(
                    x => x.Value.Properties.RuntimeId == element.Properties.RuntimeId).Key;

            if (registeredKey == null)
            {
                Interlocked.Increment(ref safeInstanceCount);

                // TODO: Maybe use RuntimeId how registeredKey?
                registeredKey = element.GetHashCode() + "-"
                                + safeInstanceCount.ToString(string.Empty, CultureInfo.InvariantCulture);
                this.registeredElements.Add(registeredKey, element);
            }

            return registeredKey;
        }
Ejemplo n.º 6
0
        internal static IEnumerable<CruciatusElement> FindAll(CruciatusElement parent, By getStrategy, int timeout)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            var element = parent.Instance;
            var info = getStrategy.FindInfoList;
            for (var i = 0; i < info.Count - 1; ++i)
            {
                element = AutomationElementHelper.FindFirst(element, info[i].TreeScope, info[i].Condition, timeout);
                if (element == null)
                {
                    Logger.Error("Element '{0}' not found", info);
                    CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
                    throw new CruciatusException("ELEMENT NOT FOUND");
                }
            }

            var lastIinfo = getStrategy.FindInfoList.Last();
            var result = AutomationElementHelper.FindAll(element, lastIinfo.TreeScope, lastIinfo.Condition);
            return result.Select(e => new CruciatusElement(parent, e, getStrategy));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Создает экземпляр списка.
 /// </summary>
 /// <param name="element">
 /// Исходный элемент.
 /// </param>
 public ListBox(CruciatusElement element)
     : base(element)
 {
 }
Ejemplo n.º 8
0
        private static void ElementCenter(CruciatusElement element, out int x, out int y)
        {
            var rect = element.Properties.BoundingRectangle;

            x = (int)(rect.Left + (rect.Width / 2));
            y = (int)(rect.Top + (rect.Height / 2));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Scroll on the touch screen using finger based motion events.
        /// </summary>
        /// <param name="element">The element to scroll</param>
        /// <param name="xOffset">The X pixels to scroll</param>
        /// <param name="yOffset">The Y pixels to scroll</param>
        /// <returns>true if successful, otherwise false</returns>
        public static bool Scroll(CruciatusElement element, int xOffset, int yOffset)
        {
            var rect = element.Properties.BoundingRectangle;

            var xStart = (int)(rect.Left + (rect.Width / 2));
            var yStart = (int)(rect.Top + (rect.Height / 2));

            var xEnd = xStart + xOffset;
            var yEnd = yStart + yOffset;

            return Scroll(xStart, yStart, xEnd, yEnd);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Long press on the touch screen using finger motion events.
        /// </summary>
        /// <param name="element">The element to long press on</param>
        /// <param name="duration">The duration of the press</param>
        /// <returns>true if successful, otherwise false</returns>
        public static bool LongTap(CruciatusElement element, int duration)
        {
            int x, y;
            ElementCenter(element, out x, out y);

            return LongTap(x, y, duration);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Finger move on the screen.
 /// </summary>
 /// <param name="element">The element to touch</param>
 /// <param name="xOffset">The X coordinate relative to the element</param>
 /// <param name="yOffset">The Y coordinate relative to the element</param>
 /// <returns>true if successful, otherwise false</returns>
 public static bool TouchUpdate(CruciatusElement element, int xOffset, int yOffset)
 {
     return ElementLocationAction(element, xOffset, yOffset, TouchUpdate);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Создает экземпляр чекбокса.
 /// </summary>
 /// <param name="element">
 /// Исходный элемент.
 /// </param>
 public CheckBox(CruciatusElement element)
     : base(element)
 {
 }
Ejemplo n.º 13
0
        private void ValuePatternSetValue(CruciatusElement element, IEnumerable<JToken> args)
        {
            var value = args.ElementAtOrDefault(1);
            if (value == null)
            {
                var msg = string.Format(HelpArgumentsErrorMsg, HelpUrlAutomationScript);
                throw new AutomationException(msg, ResponseStatus.JavaScriptError);
            }

            element.GetPattern<ValuePattern>(ValuePattern.Pattern).SetValue(value.ToString());
        }
Ejemplo n.º 14
0
 public SecondTab(CruciatusElement parent, By getStrategy)
     : base(parent, getStrategy)
 {
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Кликает по заданной кнопке диалогового окна.
        /// </summary>
        /// <param name="dialogWindow">
        /// Диалоговое окно.
        /// </param>
        /// <param name="buttonsType">
        /// Тип набора кнопок диалогово окна.
        /// </param>
        /// <param name="targetButton">
        /// Целевая кнопка.
        /// </param>
        public static void ClickButton(
            CruciatusElement dialogWindow, 
            MessageBoxButton buttonsType, 
            MessageBoxResult targetButton)
        {
            if (dialogWindow == null)
            {
                throw new ArgumentNullException("dialogWindow");
            }

            var condition = new PropertyCondition(WindowPattern.IsModalProperty, true);
            var modalwindow = AutomationElementHelper.FindFirst(dialogWindow.Instance, TreeScope.Children, condition);
            if (modalwindow == null)
            {
                throw new CruciatusException("NOT CLICK BUTTON");
            }

            string uid;
            if (targetButton == MessageBoxResult.None)
            {
                uid = CruciatusFactory.Settings.MessageBoxButtonUid.CloseButton;
            }
            else
            {
                switch (buttonsType)
                {
                    case MessageBoxButton.OK:
                        switch (targetButton)
                        {
                            case MessageBoxResult.OK:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.OkType.Ok;
                                break;
                            default:
                                throw new CruciatusException("NOT CLICK BUTTON");
                        }

                        break;

                    case MessageBoxButton.OKCancel:
                        switch (targetButton)
                        {
                            case MessageBoxResult.OK:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.OkCancelType.Ok;
                                break;
                            case MessageBoxResult.Cancel:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.OkCancelType.Cancel;
                                break;
                            default:
                                throw new CruciatusException("NOT CLICK BUTTON");
                        }

                        break;

                    case MessageBoxButton.YesNo:
                        switch (targetButton)
                        {
                            case MessageBoxResult.Yes:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoType.Yes;
                                break;
                            case MessageBoxResult.No:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoType.No;
                                break;
                            default:
                                throw new CruciatusException("NOT CLICK BUTTON");
                        }

                        break;

                    case MessageBoxButton.YesNoCancel:
                        switch (targetButton)
                        {
                            case MessageBoxResult.Yes:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoCancelType.Yes;
                                break;
                            case MessageBoxResult.No:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoCancelType.No;
                                break;
                            case MessageBoxResult.Cancel:
                                uid = CruciatusFactory.Settings.MessageBoxButtonUid.YesNoCancelType.Cancel;
                                break;
                            default:
                                throw new CruciatusException("NOT CLICK BUTTON");
                        }

                        break;

                    default:
                        throw new CruciatusException("NOT CLICK BUTTON");
                }
            }

            var buttonElement = new CruciatusElement(dialogWindow, modalwindow, null).FindElement(By.Uid(uid));
            buttonElement.Click();
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Создает экземпляр вкладки. Поиск осуществится только при необходимости.
 /// </summary>
 /// <param name="parent">
 /// Родительский элемент.
 /// </param>
 /// <param name="getStrategy">
 /// Стратегия поиска элемента.
 /// </param>
 public TabItem(CruciatusElement parent, By getStrategy)
     : base(parent, getStrategy)
 {
 }
Ejemplo n.º 17
0
 internal static CruciatusElement FindFirst(CruciatusElement parent, By getStrategy)
 {
     return FindFirst(parent, getStrategy, CruciatusFactory.Settings.SearchTimeout);
 }
Ejemplo n.º 18
0
 public FirstRibbonTab(CruciatusElement parent, By getStrategy)
     : base(parent, getStrategy)
 {
 }
Ejemplo n.º 19
0
 public MainWindow(CruciatusElement parent, By getStrategy)
     : base(parent, getStrategy)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Создает экземпляр чекбокса. Поиск осуществится только при необходимости.
 /// </summary>
 /// <param name="parent">
 /// Родительский элемент.
 /// </param>
 /// <param name="getStrategy">
 /// Стратегия поиска элемента.
 /// </param>
 public CheckBox(CruciatusElement parent, By getStrategy)
     : base(parent, getStrategy)
 {
 }
Ejemplo n.º 21
0
        internal static bool TryClickOnClickablePoint(MouseButton button, CruciatusElement element, bool doubleClick)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            var point = element.Properties.ClickablePoint;
            if (!point.HasValue)
            {
                Logger.Debug("Element '{0}' not have ClickablePoint", element);
                return false;
            }

            var x = point.Value.X;
            var y = point.Value.Y;
            if (doubleClick)
            {
                CruciatusFactory.Mouse.DoubleClick(button, x, y);
            }
            else
            {
                CruciatusFactory.Mouse.Click(button, x, y);
            }

            Logger.Info(
                "{0} on '{1}' element at ({2}, {3}) ClickablePoint", 
                doubleClick ? "DoubleClick" : "Click", 
                element, 
                x, 
                y);
            return true;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Flick on the touch screen using finger motion events.
        /// </summary>
        /// <param name="element">The element where the flick starts</param>
        /// <param name="xOffset">The X offset in pixels to flick by</param>
        /// <param name="yOffset">The Y offset in pixels to flixk by</param>
        /// <param name="pixelsPerSecond">The speed in pixels per second</param>
        /// <returns>true if successful, otherwise false</returns>
        public static bool FlickElement(CruciatusElement element, int xOffset, int yOffset, int pixelsPerSecond)
        {
            var rect = element.Properties.BoundingRectangle;

            var startPoint = new Point(
                rect.Left + (rect.Width / 2),
                rect.Top + (rect.Height / 2));

            var endPoint = new Point(
                startPoint.X + xOffset,
                startPoint.Y + yOffset);

            if (!TouchDown((int)startPoint.X, (int)startPoint.Y))
            {
                return false;
            }

            var distance = Math.Sqrt(Math.Pow(startPoint.X - endPoint.X, 2) + Math.Pow(startPoint.Y - endPoint.Y, 2));

            var gestureMilliseconds = distance / pixelsPerSecond * 1000;

            var startTime = DateTime.UtcNow;

            var iterations = 0;

            while (DateTime.UtcNow < (startTime + TimeSpan.FromMilliseconds(gestureMilliseconds)))
            {
                var elapsed = (DateTime.UtcNow - startTime).TotalMilliseconds;

                var elapsedFraction = elapsed / gestureMilliseconds;

                if (!TouchUpdate(
                        (int)(startPoint.X + (xOffset * elapsedFraction)),
                        (int)(startPoint.Y + (yOffset * elapsedFraction))))
                {
                    return false;
                }

                while ((DateTime.UtcNow - startTime).TotalMilliseconds < (iterations * 16))
                {
                    Thread.Sleep(4);
                }
            }

            return TouchUpdate((int)endPoint.X, (int)endPoint.Y)
                && TouchUp((int)endPoint.X, (int)endPoint.Y);

        }
Ejemplo n.º 23
0
        internal static bool TryClickUsingInvokePattern(CruciatusElement element, bool doubleClick)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            object basePattern;
            if (element.Instance.TryGetCurrentPattern(InvokePattern.Pattern, out basePattern))
            {
                string cmd;
                var invokePattern = (InvokePattern)basePattern;
                if (doubleClick)
                {
                    invokePattern.Invoke();
                    invokePattern.Invoke();
                    cmd = "DoubleClick";
                }
                else
                {
                    invokePattern.Invoke();
                    cmd = "Click";
                }

                Logger.Info("{0} emulation on '{1}' element with use invoke pattern", cmd, element);
                return true;
            }

            Logger.Debug("Element '{0}' not support InvokePattern", element);
            return false;
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Double tap on the touch screen using finger motion events.
 /// </summary>
 /// <param name="element">The element to double tap on</param>
 /// <returns>true if successful, otherwise false</returns>
 public static bool DoubleTap(CruciatusElement element)
 {
     return ElementCenterAction(element, DoubleTap);
 }
Ejemplo n.º 25
0
        internal static bool TryGetTextUsingTextPattern(CruciatusElement element, out string text)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            object pattern;
            if (element.Instance.TryGetCurrentPattern(TextPattern.Pattern, out pattern))
            {
                var textPattern = pattern as TextPattern;
                if (textPattern != null)
                {
                    text = textPattern.DocumentRange.GetText(-1);
                    Logger.Info("Element '{0}' return text using TextPattern", element);
                    return true;
                }
            }

            Logger.Debug("Element '{0}' not support TextPattern", element);
            text = null;
            return false;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Long press on the touch screen using finger motion events.
 /// </summary>
 /// <param name="element">The element to long press on</param>
 /// <param name="xOffset">The X offset of the element being touched</param>
 /// <param name="yOffset">The Y offset of the element being touched</param>
 /// <param name="duration">The duration of the press</param>
 /// <returns>true if successful, otherwise false</returns>
 public static bool LongTap(CruciatusElement element, int xOffset, int yOffset, int duration)
 {
     var rect = element.Properties.BoundingRectangle;
     
     return LongTap((int)(rect.Left + xOffset), (int)(rect.Top + yOffset), duration);
 }
Ejemplo n.º 27
0
        internal static bool TryGetTextUsingValuePattern(CruciatusElement element, out string text)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            object pattern;
            if (element.Instance.TryGetCurrentPattern(ValuePattern.Pattern, out pattern))
            {
                var valuePattern = pattern as ValuePattern;
                if (valuePattern != null)
                {
                    Logger.Info("Element '{0}' return text with use ValuePattern", element);
                    text = valuePattern.Current.Value;
                    return true;
                }
            }

            Logger.Debug("Element '{0}' not support ValuePattern", element);
            text = null;
            return false;
        }
Ejemplo n.º 28
0
        private static bool ElementCenterAction(CruciatusElement element, Func<int, int, bool> action)
        {
            int x, y;
            ElementCenter(element, out x, out y);

            return action(x, y);
        }
Ejemplo n.º 29
0
 internal static IEnumerable<CruciatusElement> FindAll(CruciatusElement parent, By getStrategy)
 {
     return FindAll(parent, getStrategy, CruciatusFactory.Settings.SearchTimeout);
 }
Ejemplo n.º 30
0
        private static bool ElementLocationAction(
            CruciatusElement element,
            int xOffset,
            int yOffset,
            Func<int, int, bool> action)
        {
            var rect = element.Properties.BoundingRectangle;

            return action((int)(rect.Left + xOffset), (int)(rect.Top + yOffset));
        }
Ejemplo n.º 31
0
 public MainWindow(CruciatusElement parent, By getStrategy)
     : base(parent, getStrategy)
 {
 }