コード例 #1
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)));
        }
コード例 #2
0
        internal static AutomationElement FindFirst(AutomationElement parent, By getStrategy, int timeout)
        {
            var element = parent;

            foreach (var info in getStrategy.FindInfoList)
            {
                element = AutomationElementHelper.FindFirst(element, info.TreeScope, info.Condition, timeout);
                if (element == null)
                {
                    Logger.Info("Element '{0}' not found", info);
                    CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
                    return(null);
                }
            }

            return(element);
        }
コード例 #3
0
        /// <summary>
        /// Возвращает элемент ячейки, либо null, если он не найден.
        /// </summary>
        /// <param name="row">
        /// Номер строки.
        /// </param>
        /// <param name="column">
        /// Номер колонки.
        /// </param>
        public virtual CruciatusElement Item(int row, int column)
        {
            if (!this.Instance.Current.IsEnabled)
            {
                Logger.Error("Element '{0}' not enabled. Scroll failed.", this.ToString());
                CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
                throw new ElementNotEnabledException("NOT GET ITEM");
            }

            // Проверка на дурака
            if (row < 0 || column < 0)
            {
                Logger.Error(
                    "В {0} ячейка [{1}, {2}] не существует, т.к. задан отрицательный номер.",
                    this,
                    row,
                    column);
                throw new CruciatusException("NOT GET ITEM");
            }

            // Условие для поиска ячейки [row, column]
            var cellCondition =
                new AndCondition(
                    new PropertyCondition(AutomationElement.IsGridItemPatternAvailableProperty, true),
                    new PropertyCondition(GridItemPattern.RowProperty, row),
                    new PropertyCondition(GridItemPattern.ColumnProperty, column));
            var cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);

            // Проверка, что ячейку видно
            if (cell == null || !this.Instance.ContainsClickablePoint(cell))
            {
                Logger.Error("В {0} ячейка [{1}, {2}] вне видимости или не существует.", this, row, column);
                throw new CruciatusException("NOT GET ITEM");
            }

            // Поиск подходящего элемента в ячейке
            var elem = cell.FindFirst(TreeScope.Subtree, Condition.TrueCondition);

            if (elem == null)
            {
                Logger.Error("В {0}, ячейка [{1}, {2}], нет элемента желаемого типа.", this, row, column);
                throw new CruciatusException("NOT GET ITEM");
            }

            return(new CruciatusElement(null, elem, null));
        }
コード例 #4
0
        /// <summary>
        /// Возвращает элемент ячейки, либо null, если он не найден.
        /// </summary>
        /// <param name="row">
        /// Номер строки.
        /// </param>
        /// <param name="column">
        /// Номер колонки.
        /// </param>
        public virtual CruciatusElement Item(int row, int column)
        {
            if (!this.Instance.Current.IsEnabled)
            {
                Logger.Error("Element '{0}' not enabled. Scroll failed.", this.ToString());
                CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
                throw new ElementNotEnabledException("NOT GET ITEM");
            }

            // Проверка на дурака
            if (row < 0 || column < 0)
            {
                Logger.Error("Cell index [{1}, {2}] is out of bounds for DataGrid {0}.", this, row, column);
                throw new CruciatusException("NOT GET ITEM");
            }

            // Условие для поиска ячейки [row, column]
            var cellCondition =
                new AndCondition(
                    new PropertyCondition(AutomationElement.IsGridItemPatternAvailableProperty, true),
                    new PropertyCondition(GridItemPattern.RowProperty, row),
                    new PropertyCondition(GridItemPattern.ColumnProperty, column));
            var cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);

            // Проверка, что ячейку видно
            if (cell == null || !this.Instance.ContainsClickablePoint(cell))
            {
                Logger.Error("Cell [{1}, {2}] is not visible in DataGrid {0}.", this, row, column);
                throw new CruciatusException("NOT GET ITEM");
            }

            // Поиск подходящего элемента в ячейке
            var elem = cell.FindFirst(TreeScope.Subtree, Condition.TrueCondition);

            if (elem == null)
            {
                Logger.Error("Item not found in cell [{1}, {2}] for DataGrid {0}.", this, row, column);
                throw new CruciatusException("NOT GET ITEM");
            }

            return(new CruciatusElement(null, elem, null));
        }
コード例 #5
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();
        }
コード例 #6
0
        /// <summary>
        /// Прокручивает таблицу до ячейки.
        /// </summary>
        /// <param name="row">
        /// Номер строки.
        /// </param>
        /// <param name="column">
        /// Номер колонки.
        /// </param>
        public virtual void ScrollTo(int row, int column)
        {
            if (!this.Instance.Current.IsEnabled)
            {
                Logger.Error("Element '{0}' not enabled. Scroll failed.", this.ToString());
                CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
                throw new ElementNotEnabledException("NOT SCROLL");
            }

            // Проверка на дурака
            if (row < 0 || column < 0)
            {
                var msg = string.Format("Cell index [{1}, {2}] is out of bounds for DataGrid {0}.", this, row, column);
                Logger.Error(msg);
                throw new CruciatusException("NOT SCROLL");
            }

            var scrollPattern = this.Instance.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;

            if (scrollPattern == null)
            {
                Logger.Error("{0} does not support ScrollPattern.", this.ToString());
                throw new CruciatusException("NOT SCROLL");
            }

            // Условие для вертикального поиска ячейки [row, 0] (через строку)
            var cellCondition =
                new AndCondition(
                    new PropertyCondition(AutomationElement.IsGridItemPatternAvailableProperty, true),
                    new PropertyCondition(GridItemPattern.RowProperty, row));

            // Стартовый поиск ячейки
            var cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);

            // Вертикальная прокрутка (при необходимости и возможности)
            if (cell == null && scrollPattern.Current.VerticallyScrollable)
            {
                // Установка самого верхнего положения прокрутки
                while (scrollPattern.Current.VerticalScrollPercent > 0.1)
                {
                    scrollPattern.ScrollVertical(ScrollAmount.LargeIncrement);
                }

                // Установка самого левого положения прокрутки (при возможности)
                if (scrollPattern.Current.HorizontallyScrollable)
                {
                    while (scrollPattern.Current.HorizontalScrollPercent > 0.1)
                    {
                        scrollPattern.ScrollHorizontal(ScrollAmount.LargeIncrement);
                    }
                }

                // Основная вертикальная прокрутка
                while (cell == null && scrollPattern.Current.VerticalScrollPercent < 99.9)
                {
                    scrollPattern.ScrollVertical(ScrollAmount.LargeIncrement);
                    cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);
                }
            }

            // Если прокрутив до конца ячейка не найдена, то номер строки не действительный
            if (cell == null)
            {
                Logger.Error("Row index {1} is out of bounds for {0}.", this, row);
                throw new CruciatusException("NOT SCROLL");
            }

            // Если точка клика ячейки [row, 0] под границей таблицы - докручиваем по вертикали вниз
            while (cell.ClickablePointUnder(this.Instance, scrollPattern))
            {
                scrollPattern.ScrollVertical(ScrollAmount.SmallIncrement);
            }

            // Если точка клика ячейки [row, 0] над границей таблицы - докручиваем по вертикали вверх
            while (cell.ClickablePointOver(this.Instance))
            {
                scrollPattern.ScrollVertical(ScrollAmount.SmallDecrement);
            }

            // Условие для горизонтального поиска ячейки [row, column]
            cellCondition =
                new AndCondition(
                    new PropertyCondition(AutomationElement.IsGridItemPatternAvailableProperty, true),
                    new PropertyCondition(GridItemPattern.RowProperty, row),
                    new PropertyCondition(GridItemPattern.ColumnProperty, column));

            // Стартовый поиск ячейки
            cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);

            // Основная горизонтальная прокрутка (при необходимости и возможности)
            if (cell == null && scrollPattern.Current.HorizontallyScrollable)
            {
                while (cell == null && scrollPattern.Current.HorizontalScrollPercent < 99.9)
                {
                    scrollPattern.ScrollHorizontal(ScrollAmount.LargeIncrement);
                    cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);
                }
            }

            // Если прокрутив до конца ячейка не найдена, то номер колонки не действительный
            if (cell == null)
            {
                Logger.Error("Column index {1} is out of bounds for DataGrid {0}.", this, column);
                throw new CruciatusException("NOT SCROLL");
            }

            // Если точка клика ячейки [row, column] справа от границы таблицы - докручиваем по горизонтали вправо
            while (cell.ClickablePointRight(this.Instance, scrollPattern))
            {
                scrollPattern.ScrollHorizontal(ScrollAmount.SmallIncrement);
            }

            // Если точка клика ячейки [row, column] слева от границы таблицы - докручиваем по горизонтали влево
            while (cell.ClickablePointLeft(this.Instance))
            {
                scrollPattern.ScrollHorizontal(ScrollAmount.SmallDecrement);
            }
        }
コード例 #7
0
ファイル: DataGrid.cs プロジェクト: sainm/WindowsAppDriver
        public virtual void ScrollTo(int row, int column)
        {
            if (!this.Instance.Current.IsEnabled)
            {
                Logger.Error("Element '{0}' not enabled. Scroll failed.", this.ToString());
                CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
                throw new ElementNotEnabledException("NOT SCROLL");
            }

            if (row < 0 || column < 0)
            {
                var msg = string.Format("Cell index [{1}, {2}] is out of bounds for DataGrid {0}.", this, row, column);
                Logger.Error(msg);
                throw new CruciatusException("NOT SCROLL");
            }

            var scrollPattern = this.Instance.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;

            if (scrollPattern == null)
            {
                Logger.Error("{0} does not support ScrollPattern.", this.ToString());
                throw new CruciatusException("NOT SCROLL");
            }

            var cellCondition =
                new AndCondition(
                    new PropertyCondition(AutomationElement.IsGridItemPatternAvailableProperty, true),
                    new PropertyCondition(GridItemPattern.RowProperty, row));

            var cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);

            if (cell == null && scrollPattern.Current.VerticallyScrollable)
            {
                while (scrollPattern.Current.VerticalScrollPercent > 0.1)
                {
                    scrollPattern.ScrollVertical(ScrollAmount.LargeIncrement);
                }

                if (scrollPattern.Current.HorizontallyScrollable)
                {
                    while (scrollPattern.Current.HorizontalScrollPercent > 0.1)
                    {
                        scrollPattern.ScrollHorizontal(ScrollAmount.LargeIncrement);
                    }
                }

                while (cell == null && scrollPattern.Current.VerticalScrollPercent < 99.9)
                {
                    scrollPattern.ScrollVertical(ScrollAmount.LargeIncrement);
                    cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);
                }
            }

            if (cell == null)
            {
                Logger.Error("Row index {1} is out of bounds for {0}.", this, row);
                throw new CruciatusException("NOT SCROLL");
            }

            while (cell.ClickablePointUnder(this.Instance, scrollPattern))
            {
                scrollPattern.ScrollVertical(ScrollAmount.SmallIncrement);
            }

            while (cell.ClickablePointOver(this.Instance))
            {
                scrollPattern.ScrollVertical(ScrollAmount.SmallDecrement);
            }

            cellCondition =
                new AndCondition(
                    new PropertyCondition(AutomationElement.IsGridItemPatternAvailableProperty, true),
                    new PropertyCondition(GridItemPattern.RowProperty, row),
                    new PropertyCondition(GridItemPattern.ColumnProperty, column));

            cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);

            if (cell == null && scrollPattern.Current.HorizontallyScrollable)
            {
                while (cell == null && scrollPattern.Current.HorizontalScrollPercent < 99.9)
                {
                    scrollPattern.ScrollHorizontal(ScrollAmount.LargeIncrement);
                    cell = AutomationElementHelper.FindFirst(this.Instance, TreeScope.Subtree, cellCondition);
                }
            }

            if (cell == null)
            {
                Logger.Error("Column index {1} is out of bounds for DataGrid {0}.", this, column);
                throw new CruciatusException("NOT SCROLL");
            }

            while (cell.ClickablePointRight(this.Instance, scrollPattern))
            {
                scrollPattern.ScrollHorizontal(ScrollAmount.SmallIncrement);
            }

            while (cell.ClickablePointLeft(this.Instance))
            {
                scrollPattern.ScrollHorizontal(ScrollAmount.SmallDecrement);
            }
        }
コード例 #8
0
 internal override AutomationElement FindFirst(AutomationElement parent, int timeout)
 {
     return(AutomationElementHelper.FindFirst(parent, this.scope, this.GetCondition(), timeout));
 }