Exemple #1
0
        public AutomationElement GetCell(AutomationElement dataItem)
        {
            ScrollItemPattern scroll = (ScrollItemPattern)dataItem.GetCurrentPattern(ScrollItemPattern.Pattern);

            scroll.ScrollIntoView();

            // find the DataGridCell to activate.
            int index = this.index;

            if (this.Parent != null)
            {
                index = this.Parent.index;
            }

            int i = 0;
            AutomationElement cell = null;

            foreach (AutomationElement e in dataItem.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "DataGridCell")))
            {
                if (i == index)
                {
                    cell = e;
                    break;
                }
                i++;
            }

            if (cell == null)
            {
                throw new Exception("Expecting a DataGridCell to appear at index " + index + " in the DataItem" + Name + ". We found " + i + " DataGridCells.");
            }

            return(cell);
        }
Exemple #2
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal ScrollItemPatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
            :
            base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
        {
            Comment("Creating ScrollItemTests");

            _pattern = (ScrollItemPattern)GetPattern(m_le, m_useCurrent, ScrollItemPattern.Pattern);
            if (_pattern == null)
            {
                ThrowMe(CheckType.IncorrectElementConfiguration, Helpers.PatternNotSupported + ": ScrollItemPattern");
            }

            // Find the ScrollPattern
            _container = m_le;

            while (_container != null && !(bool)_container.GetCurrentPropertyValue(AutomationElement.IsScrollPatternAvailableProperty))
            {
                _container = TreeWalker.ControlViewWalker.GetParent(_container);
            }

            // Check to see if we actual found the container of the scrollitem
            if (_container == null)
            {
                ThrowMe(CheckType.IncorrectElementConfiguration, "Element does not have a container with ScrollPattern");
            }

            Comment("Found scroll container: " + Library.GetUISpyLook(_container));

            _scrollPattern = (ScrollPattern)_container.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;
        }
Exemple #3
0
        public static bool TryGetScrollItemPattern(this AutomationElement element, out ScrollItemPattern result)
        {
            if (element.TryGetCurrentPattern(System.Windows.Automation.ScrollItemPattern.Pattern, out var pattern))
            {
                result = (ScrollItemPattern)pattern;
                return(true);
            }

            result = null;
            return(false);
        }
Exemple #4
0
        public void ScrollIntoView(bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Scroll {0} into view.", this.NameAndType));
            }

            ScrollItemPattern sip = (ScrollItemPattern)element.GetCurrentPattern(ScrollItemPattern.Pattern);

            sip.ScrollIntoView();
        }
        public static void EnsureElementIsScrolledIntoView(this AutomationElement element)
        {
            if (!(bool)element.GetCurrentPropertyValue(AutomationElement.IsScrollItemPatternAvailableProperty))
            {
                return;
            }

            ScrollItemPattern scrollItemPattern = element.GetScrollItemPattern();

            scrollItemPattern.ScrollIntoView();
        }
Exemple #6
0
 public static bool ScrollTo(AutoElem e)
 {
     if (e.TryGetCurrentPattern(ScrollItemPattern.Pattern, out object obj))
     {
         ScrollItemPattern Pattern = obj as ScrollItemPattern;
         Pattern.ScrollIntoView();
         Console.WriteLine("scrolled to");
         return(true);
     }
     else
     {
         return(false);
     }
 }
        private void ScrollPeopleListPrivate(string listViewId)
        {
            using (var setup = new TestSetupHelper("PersonPicture Tests"))
            {
                Log.Comment("Finding ListView");
                ListView peopleListView = new ListView(FindElement.ById(listViewId));
                Verify.IsNotNull(peopleListView, "ListView found");

                Log.Comment("Retrieving first ListView");
                ListViewItem firstLVI = peopleListView.AllItems[0];
                Verify.IsNotNull(firstLVI, "First ListViewItem retrieved");

                Log.Comment("Retrieving fifth ListView at index 4");
                ListViewItem fifthLVI = peopleListView.AllItems[4];
                Verify.IsNotNull(fifthLVI, "Fifth ListViewItem retrieved");

                Verify.IsFalse(firstLVI.IsOffscreen, "First item is on screen");
                Verify.IsTrue(fifthLVI.IsOffscreen, "Fifth item is off screen");

                firstLVI.SetFocus();
                Wait.ForIdle();

                AutomationElement firstItemAE = AutomationElement.FocusedElement;

                fifthLVI.SetFocus();
                Wait.ForIdle();

                AutomationElement fifthItemAE = AutomationElement.FocusedElement;

                Log.Comment("Scroll to the fifth item using the automation ScrollItemPattern");
                ScrollItemPattern fifthItemSIP = fifthItemAE.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern;
                fifthItemSIP.ScrollIntoView();
                Wait.ForIdle();

                Verify.IsTrue(firstLVI.IsOffscreen, "First item is off screen");
                Verify.IsFalse(fifthLVI.IsOffscreen, "Fifth item is on screen");

                Log.Comment("Scroll back to the first item using the automation ScrollItemPattern");
                ScrollItemPattern firstItemSIP = firstItemAE.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern;
                firstItemSIP.ScrollIntoView();
                Wait.ForIdle();

                Verify.IsFalse(firstLVI.IsOffscreen, "First item is on screen");
                Verify.IsTrue(fifthLVI.IsOffscreen, "Fifth item is off screen");
            }
        }
Exemple #8
0
        public static void ScrollIntoView(AutomationElement ae)
        {
            try
            {
                ScrollItemPattern pattern = ae.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern;

                if (null == pattern)
                {
                    return;
                }

                pattern.ScrollIntoView();
            }
            catch
            {
            }
        }
        // <Snippet100>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Obtains a ScrollItemPattern control pattern from an
        /// automation element.
        /// </summary>
        /// <param name="targetControl">
        /// The automation element of interest.
        /// </param>
        /// <returns>
        /// A ScrollItemPattern object.
        /// </returns>
        ///--------------------------------------------------------------------
        private ScrollItemPattern GetScrollItemPattern(
            AutomationElement targetControl)
        {
            ScrollItemPattern scrollItemPattern = null;

            try
            {
                scrollItemPattern =
                    targetControl.GetCurrentPattern(
                        ScrollItemPattern.Pattern)
                    as ScrollItemPattern;
            }
            // Object doesn't support the ScrollItemPattern control pattern
            catch (InvalidOperationException)
            {
                return(null);
            }

            return(scrollItemPattern);
        }
        // </Snippet100>

        // <Snippet101>
        ///--------------------------------------------------------------------
        /// <summary>
        /// A Select, AddToSelection or RemoveFromSelection event handler that
        /// scrolls a SelectionItem object into the viewable region of its
        /// container control.
        /// </summary>
        ///--------------------------------------------------------------------
        private void OnSelectionItemSelect(
            object src, SelectionChangedEventArgs e)
        {
            AutomationElement selectionItem = src as AutomationElement;

            ScrollItemPattern scrollItemPattern = GetScrollItemPattern(selectionItem);

            if (scrollItemPattern == null)
            {
                return;
            }

            try
            {
                scrollItemPattern.ScrollIntoView();
            }
            catch (InvalidOperationException)
            {
                // The item cannot be scrolled into view.
                // TO DO: error handling.
            }
        }
Exemple #11
0
        public void ScrollIntoView()
        {
            ScrollItemPattern scroll = (ScrollItemPattern)item.GetCurrentPattern(ScrollItemPattern.Pattern);

            scroll.ScrollIntoView();
        }
Exemple #12
0
 public GridRow ScrollIntoView()
 {
     ScrollItemPattern?.ScrollIntoView();
     return(this);
 }
 public static void xtScrollIntoView(this UIItem item)
 {
     patt_ScrollItemPattern = Retry.For(() => ((ScrollItemPattern)item.AutomationElement.GetCurrentPattern(ScrollItemPattern.Pattern)), TimeSpan.FromSeconds(10));
     patt_ScrollItemPattern.ScrollIntoView();
 }
Exemple #14
0
        private static void Main(string[] args)
        {
            IntPtr            hwnd     = new IntPtr(1248584);
            AutomationElement element  = AutomationElement.FromHandle(hwnd);
            AutomationElement deskTop  = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "回收站"));
            AutomationElement deskTop1 = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "计算机"));
            AutomationElement deskTop2 = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "Administrator"));
            AutomationElement deskTop3 = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "aliPdf"));

            AutomationElement deskTop4 = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "Dlls"));

            //AutomationElement deskTop4 = element.FindFirst(TreeScope.Ancestors, new PropertyCondition(AutomationElement.NameProperty, "全选"));
            //AutomationElement deskTop5 = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "上传"));
            StringBuilder suportSb = new StringBuilder();

            AutomationPattern[] allPaternTmp = deskTop3.GetSupportedPatterns();
            foreach (AutomationPattern item in allPaternTmp)
            {
                var    clickPattern = deskTop.GetCurrentPattern(item);
                String curPatern    = clickPattern.ToString();
                suportSb.AppendLine(curPatern);
            }
            ExpandCollapsePattern tmpPatrn1 = (ExpandCollapsePattern)deskTop3.GetCurrentPattern(ExpandCollapsePattern.Pattern);
            SelectionItemPattern  tmpPatrn2 = (SelectionItemPattern)deskTop3.GetCurrentPattern(SelectionItemPattern.Pattern);
            ScrollItemPattern     tmpPatrn3 = (ScrollItemPattern)deskTop3.GetCurrentPattern(ScrollItemPattern.Pattern);
            String tmp = suportSb.ToString();

            SelectionItemPattern tmpPatrn42 = (SelectionItemPattern)deskTop4.GetCurrentPattern(SelectionItemPattern.Pattern);

            Thread.Sleep(1000);

            tmpPatrn2.Select();

            Thread.Sleep(1000);

            tmpPatrn42.Select();


            Thread.Sleep(1000);

            tmpPatrn2.Select();

            Thread.Sleep(1000);

            tmpPatrn42.Select();



            //StringBuilder suportSb4 = new StringBuilder();
            //AutomationPattern[] allPaternTmp4 = deskTop4.GetSupportedPatterns();
            //foreach (AutomationPattern item in allPaternTmp4)
            //{
            //    var clickPattern = deskTop4.GetCurrentPattern(item);
            //    String curPatern = clickPattern.ToString();
            //    suportSb.AppendLine(curPatern);
            //}
            ////ExpandCollapsePattern tmpPatrn14 = (ExpandCollapsePattern)deskTop3.GetCurrentPattern(ExpandCollapsePattern.Pattern);
            ////SelectionItemPattern tmpPatrn24 = (SelectionItemPattern)deskTop3.GetCurrentPattern(SelectionItemPattern.Pattern);
            ////ScrollItemPattern tmpPatrn34 = (ScrollItemPattern)deskTop3.GetCurrentPattern(ScrollItemPattern.Pattern);
            //String tmp4 = suportSb.ToString();



            //AutomationPattern[] allPatern = deskTop.GetSupportedPatterns();

            //foreach (AutomationPattern item in allPatern)
            //{
            //    var clickPattern = deskTop.GetCurrentPattern(item);
            //    String curPatern = clickPattern.ToString();
            //}

            //ExpandCollapsePattern tmpPatrn = (ExpandCollapsePattern)deskTop.GetCurrentPattern(ExpandCollapsePattern.Pattern);

            //Thread.Sleep(1000);
            //tmpPatrn.Expand();
            //Thread.Sleep(1000);
            //tmpPatrn.Collapse();


            //Thread.Sleep(1000);
            //tmpPatrn.Expand();
            //Thread.Sleep(1000);
            //tmpPatrn.Collapse();



            //Thread.Sleep(1000);
            //tmpPatrn.Expand();
            //Thread.Sleep(1000);
            //tmpPatrn.Collapse
            //clickPattern.Invoke();
            //System.Windows.Point point = deskTop.GetClickablePoint();

            //var obj = deskTop.GetClickablePoint();
            //WindowFormAPI.SendMessage(pc, WindowFormAPI.BM_CLICK, IntPtr.Zero, "");
            //int[] ids1 = deskTop1.GetRuntimeId();
            //element = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "桌面"));
            //if (element != null && element.Current.IsEnabled)
            //{
            //    ValuePattern vpTextEdit = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
            //    if (vpTextEdit != null)
            //    {
            //        string value = vpTextEdit.Current.Value;
            //        Console.WriteLine(value);
            //        MessageBox.Show(value);
            //    }
            //}

            //Console.Title = string.Empty;
            //Console.WriteLine("scan the QQ user's session window.");
            //int[] hWndOfSession = Win32Native.GetSessionWindow();
            //if (hWndOfSession.Length <= 0)
            //    Console.WriteLine("No scan to any available QQ message window.");
            //else
            //{
            //    Console.WriteLine("Look for the session record interface.");
            //    foreach (int hWnd in hWndOfSession)
            //        FindUserMessage((IntPtr)hWnd);
            //}
            //Console.WriteLine("Thank you for using, QQ conversations have been scanned.");
            //Console.WriteLine("OK!");
            //Console.ReadKey(false);
        }
 public ScrollItemPatternPropertyObject(ScrollItemPattern pattern)
 {
     this._pattern = pattern;
 }
        /// <summary>
        ///     Scrolls the content area of a container object in order to display the control within the visible region (viewport) of the container.
        /// </summary>
        /// <param name = "control">The UI Automation element</param>
        /// <remarks>
        ///     This method does not provide the ability to specify the position of the control within the visible region (viewport) of the container
        /// </remarks>
        internal static void ScrollIntoView(AutomationElement control)
        {
            ScrollItemPattern pat = (ScrollItemPattern)CommonUIAPatternHelpers.CheckPatternSupport(ScrollItemPattern.Pattern, control);

            pat.ScrollIntoView();
        }