FindAll() public method

public FindAll ( TreeScope scope, Condition condition ) : AutomationElementCollection
scope TreeScope
condition Condition
return AutomationElementCollection
Beispiel #1
1
 public static void TextPatternRangeFromChildGood(AutomationElement element)
 {
     object patternObj = null;
     if (GetPatternObject(element, TextPattern.Pattern, ref patternObj))
     {
         TextPattern pattern = (TextPattern)patternObj;
         Dump("TextPattern.GetVisibleRanges", true, element);
         try
         {
             AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, Condition.TrueCondition);
             object property = pattern.RangeFromChild(collection[_rnd.Next(collection.Count)]);
         }
         catch (Exception exception)
         {
             VerifyException(element, exception,
                 typeof(ElementNotAvailableException),
                 typeof(InvalidOperationException));
         }
     }
 }
        private static void RunTestInternal(IEnumerable<AutomationTest> automationTests, AutomationElement element, IWin32Window parentWindow, AutomationTestManager manager)
        {
            //create window
            RunningTestsWindow testWindow = new RunningTestsWindow();

            if (manager._testChildren)
            {
                //// Determine if this is a control/pattern/Automation test
                //// Construct the PropertyCondition
                Condition condition = null;

                //// Add all the tests
                foreach (AutomationTest test in automationTests)
                {

                    // The tests are within a class the defines what pattern type this in is
                    StringBuilder buffer = new StringBuilder(((MainWindow)parentWindow)._automationTests._testsTreeView.SelectedNode.FullPath);
                    switch (test.Type)
                    {
                        case TestTypes.AutomationElementTest:
                            // Tests\Automation Element Tests\Priority 2 Tests\AutomationElement.PropertyChange.Enabled.1
                            condition = Condition.TrueCondition;
                            break;
                        case TestTypes.ControlTest:
                            {
                                // Tests\Control Tests\Slider\Priority 1 Tests\BulkAdd.1
                                buffer.Replace(@"Tests\Control Tests\", "");
                                int indexOf = buffer.ToString().IndexOf(@"\");
                                buffer.Remove(indexOf, buffer.Length - indexOf);
                                condition = new PropertyCondition(AutomationElement.ControlTypeProperty, GetControlType(buffer.ToString()));
                            }
                            break;
                        case TestTypes.PatternTest:
                            {
                                // Tests\Pattern Tests\Grid\Priority 1 Tests\GridPattern.S.1.1/2/3
                                buffer.Replace(@"Tests\Pattern Tests\", "");
                                int indexOf = buffer.ToString().IndexOf(@"\");
                                buffer.Remove(indexOf, buffer.Length - indexOf);
                                condition = new PropertyCondition(GetProperty("Is" + buffer.ToString() + "PatternAvailableProperty"), true);
                            }
                            break;
                        default:
                            throw new ArgumentException("Cannot run " + test.Type + " tests");

                    }
                    //// Find all elements
                    AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, condition);
                    foreach (AutomationElement temp in collection)
                        testWindow.AddTest(test, temp);
                }

            }
            else
            {
                //add all tests
                foreach (AutomationTest test in automationTests)
                    testWindow.AddTest(test, element);
            }
            //let them run
            testWindow.ShowAndRunTests(manager, parentWindow);
        }
 // 指定したName属性に一致するAutomationElementをすべて返します
 private static IEnumerable<AutomationElement> FindElementsByName(AutomationElement rootElement, string name)
 {
     return rootElement.FindAll(
         TreeScope.Element | TreeScope.Descendants,
         new PropertyCondition(AutomationElement.NameProperty, name))
         .Cast<AutomationElement>();
 }
 public AutomationElementCollection GetAllChildNodes(AutomationElement element, AutomationProperty automationProperty, object value, TreeScope treeScope)
 {
     var allChildNodes = element.FindAll(treeScope, GetPropertyCondition(automationProperty, value));
     if (allChildNodes == null)
         throw new ElementNotAvailableException("Not able to find the child nodes of the element");
     return allChildNodes;
 }
        public static AutomationElementCollection FindElementByClassName(AutomationElement parentElement, string className, ControlType type)
        {
            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            PropertyCondition IDCondition = new PropertyCondition(AutomationElement.ClassNameProperty, className);

            AndCondition andCondition = new AndCondition(typeCondition, IDCondition);

            return parentElement.FindAll(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
Beispiel #6
0
        public void DoOperations()
        {
            Process[] p = Process.GetProcessesByName("pcsws");

            //System.Windows.Automation.AutomationElement t = WinFormAdapter.GetAEFromHandle(p[0].MainWindowHandle);
            System.Windows.Automation.AutomationElement _0 = AutomationElement.FromHandle(p[0].MainWindowHandle);

            //System.Windows.Automation.AutomationElement t1 = WinFormAdapter.GetAEOnChildByName(t, "Sesión A - [24 x 80]");
            //System.Windows.Automation.AutomationElement t1 = t.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Inicio de sesión de IBM i"));

            //TODO: Obtener por tipo de elemento (Tipo.Edit)
            //Al tener el mismo nombre tanto el label como el textbox de un campo, toma los dos, al parecer el segundo siempre es el textbox....
            System.Windows.Automation.AutomationElementCollection _0_Descendants_1 = _0.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "ID de usuario:"));
            WinFormAdapter.SetText(_0_Descendants_1[1], "BFPJUARUI");

            System.Windows.Automation.AutomationElementCollection _0_Descendants_2 = _0.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Contraseña:"));
            WinFormAdapter.SetText(_0_Descendants_2[1], "BFPJUARUI2");

            WinFormAdapter.ClickElement(WinFormAdapter.GetAEOnDescByName(_0, "Aceptar"));
        }
Beispiel #7
0
 /// <summary>
 /// 启动 被测试程序.
 /// </summary>
 public void StartApp()
 {
     Console.WriteLine("尝试启动程序:[{0}]", APP_NAME);
     // 启动被测试的程序
     process = Process.Start(APP_NAME);
     // 当前线程休眠2秒.
     Thread.Sleep(DEFAULT_SLEEP_TIME);
     // 获得对主窗体对象的引用
     testMainForm = AutomationElement.FromHandle(process.MainWindowHandle);
     // 计算器层次下,首先是一个 Pane.
     AutomationElementCollection panes = testMainForm.FindAll(TreeScope.Children,
             new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane));
     // 获取主窗体上的所有按钮.
     testAllButtons = panes[0].FindAll(TreeScope.Children,
             new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
     // 获取主窗体上的所有文本框.
     testAllText = panes[0].FindAll(TreeScope.Children,
             new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));
 }
        internal static IEnumerable<AutomationElement> FindAll(
            AutomationElement parent, 
            TreeScope scope, 
            Condition condition, 
            int timeout)
        {
            var dtn = DateTime.Now.AddMilliseconds(timeout);

            // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            while (DateTime.Now <= dtn)
            {
                var elements = parent.FindAll(scope, condition);
                if (elements.Count > 0)
                {
                    return elements.Cast<AutomationElement>();
                }
            }

            return Enumerable.Empty<AutomationElement>();
        }
Beispiel #9
0
        private string GetCurrentUrl(AutomationElement chrome)
        {
            try
            {
                string url = null;

                var edits = chrome.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
                if (edits.Count == 0) return null;

                foreach (AutomationElement edit in edits)
                {
                    url = ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;

                    if (!string.IsNullOrWhiteSpace(url))
                        return base.GetUrl(url);
                }
            }
            catch
            { }

            return null;
        }
Beispiel #10
0
        public static AutomationElement GetChildren(AutomationElement parent, string NameStartsWith = "", string ControlTypeStartsWith = "")
        {
            if (parent == null) {
                throw new ArgumentException();
            }
            AutomationElementCollection collection = parent.FindAll(TreeScope.Children, Condition.TrueCondition);
            if (collection != null) {
                //Cast AutomationElementCollection into
                //AutomationElement List
                List<AutomationElement> aeList = new List<AutomationElement>(collection.Cast<AutomationElement>());
                AutomationElement aeSelected = null;

                if (NameStartsWith == "" && ControlTypeStartsWith == "") return null;

                if (NameStartsWith != "" && ControlTypeStartsWith == "") {
                    aeSelected = aeList.FirstOrDefault(i => i.Current.Name.Contains(NameStartsWith));
                }
                if (NameStartsWith == "" && ControlTypeStartsWith != "") {
                    aeSelected = aeList.FirstOrDefault(i => i.Current.LocalizedControlType.Contains(ControlTypeStartsWith));
                }
                if (NameStartsWith != "" && ControlTypeStartsWith != "") {
                    aeSelected = aeList.FirstOrDefault(i => i.Current.Name.Contains(NameStartsWith));
                    if (aeSelected == null) aeSelected = aeList.FirstOrDefault(i => i.Current.LocalizedControlType.Contains(ControlTypeStartsWith));
                }

                if (aeSelected != null)
                    return aeSelected;
                else {
                    return null;
                }

            } else {
                // some error occured
                return null;
            }
        }
        //**************************************************************************************************************************************************************


        public static void UIA_ClickButtonByName(AutomationElement uiaWindow, Window window, string name)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);
            try
            {
                PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
                AutomationElementCollection buttons = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
                foreach (AutomationElement e in buttons)
                {
                    if (e.Current.Name.Equals(name))
                    {
                        TestStack.White.UIItems.Button t = new TestStack.White.UIItems.Button(e, window.ActionListener);
                        t.Click();
                    }
                }
                Thread.Sleep(int.Parse(Execution_Speed));
                Logger.logMessage("UIA_ClickButtonByName " + uiaWindow + "->" + window + "->" + name + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

            }
            catch (Exception e)
            {
                Logger.logMessage("UIA_ClickButtonByName " + uiaWindow + "->" + window + "->" + name + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
Beispiel #12
0
 internal void SearchByTextViaUIA(
     GetControlCmdletBase cmdlet,
     AutomationElement inputObject,
     System.Windows.Automation.AndCondition conditionsForTextSearch)
 {
     this.WriteVerbose(cmdlet, "Text search");
     AutomationElementCollection textSearchCollection = inputObject.FindAll(TreeScope.Descendants, conditionsForTextSearch);
     if (null != textSearchCollection && 0 < textSearchCollection.Count) {
         this.WriteVerbose(cmdlet, "There are " + textSearchCollection.Count.ToString() + " elements");
         foreach (AutomationElement element in textSearchCollection) {
             aeCtrl.Add(element);
         }
     }
 }
Beispiel #13
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal ArrayList HelperGetContainersSelectableItems(AutomationElement selectionContainer)
        {
            ArrayList list = new ArrayList();

            // Win32 radio buttons do not have containers, so bail.
            if (selectionContainer != null)
            {

                PropertyCondition pc = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);

                foreach (AutomationElement element in selectionContainer.FindAll(TreeScope.Subtree, pc))
                {
                    // Don't want to include any "Previous" in calendar controls
                    if (element.Current.AutomationId.IndexOf("Previous") == -1 && element.Current.AutomationId.IndexOf("Next") == -1)
                    {
                        list.Add(element);
                    }
                }
            }
            return list;
        }
Beispiel #14
0
        internal void SearchByExactConditionsViaUIA(
            GetControlCmdletBase cmdlet,
            AutomationElement inputObject,
            System.Windows.Automation.AndCondition conditions)
        {
            #region the -First story
            // 20120824
            //aeCtrl =
            // 20120921
            #region -First
            //                                    if (cmdlet.First) {
            //                                        AutomationElement tempFirstElement =
            //                                            inputObject.FindFirst(
            //                                                System.Windows.Automation.TreeScope.Descendants,
            //                                                conditions);
            //                                        if (null != tempFirstElement) {
            //                                            if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
            //                                                aeCtrl.Add(tempFirstElement);
            //                                            } else {
            //                                                if (testControlWithAllSearchCriteria(
            //                                                    cmdlet,
            //                                                    cmdlet.SearchCriteria,
            //                                                    tempFirstElement)) {
            //                                                    aeCtrl.Add(tempFirstElement);
            //                                                }
            //                                            }
            //                                        }
            //                                    } else {
            #endregion -First
            // 20120823
            //cmdlet.InputObject.FindFirst(System.Windows.Automation.TreeScope.Descendants,

            // 20120824
            // 20120917
            #region -First
            //                                    }
            #endregion -First
            //else if (UIAutomation.CurrentData.LastResult
            #endregion the -First story

            //internal void SearchByExactConditionsViaUIA(System.Windows.Automation.AndCondition conditions, ref bool notTextSearch, ref System.Windows.Automation.AndCondition conditionsForWildCards, ref AutomationElement inputObject, ref int processId, GetControlCmdletBase cmdlet)
            //{

            if (conditions != null) {
                if (inputObject != null && (int)inputObject.Current.ProcessId > 0) {
                    AutomationElementCollection tempCollection = inputObject.FindAll(System.Windows.Automation.TreeScope.Descendants, conditions);
                    foreach (AutomationElement tempElement in tempCollection) {
                        if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
                            aeCtrl.Add(tempElement);
                            cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
                        } else {
                            cmdlet.WriteVerbose(cmdlet, "ExactSearch: checking search criteria");
                            if (testControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement)) {
                                cmdlet.WriteVerbose(cmdlet, "ExactSearch: the control matches the search criteria");
                                aeCtrl.Add(tempElement);
                                cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
                            }
                        }
                    }
                }
            }
        }
Beispiel #15
0
        //**************************************************************************************************************************************************************
        public static AutomationElement UIA_GetChildWindow(AutomationElement appWindow, string childWindowName)
        {
            AutomationElement childWindow = null;

            try
            {
                PropertyCondition windowTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
                PropertyCondition windowNameCondition = new PropertyCondition(AutomationElement.NameProperty, childWindowName);
                AndCondition windowCondition = new AndCondition(windowTypeCondition, windowNameCondition);
                AutomationElement window = appWindow.FindFirst(TreeScope.Children, windowCondition);

                AutomationElementCollection windows = appWindow.FindAll(TreeScope.Descendants, windowTypeCondition);

                foreach (AutomationElement w in windows)
                {
                    if (w.Current.Name.Equals(childWindowName) || w.Current.Name.Contains(childWindowName))
                    {
                        childWindow = w;
                        break;
                    }
                }

                return childWindow;
            }
            catch (Exception e)
            {
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }
Beispiel #16
0
        //**************************************************************************************************************************************************************
        public static void UIA_SetFocusOfFirstTextBox(AutomationElement uiaWindow, Window window)
        {
            try
            {
                PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text);
                AutomationElementCollection textBoxes = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
                foreach (AutomationElement textBox in textBoxes)
                {
                    TestStack.White.UIItems.TextBox t = new TestStack.White.UIItems.TextBox(textBox, window.ActionListener);
                    t.Focus();
                    t.Click();
                    Thread.Sleep(int.Parse(Execution_Speed));
                    break;
                }

            }
            catch (Exception e)
            {
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }
Beispiel #17
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TS_UnselectAll(AutomationElement container, CheckType checkType)
        {

            AutomationElementCollection aec = container.FindAll(TreeScope.Descendants, new PropertyCondition(SelectionItemPattern.IsSelectedProperty, true));
            Comment("Before removing selection, there are currently " + aec.Count + " items selected");
#if NATIVE_UIA
            for (int i=0; i < aec.Count; i++)
            {
                AutomationElement element = aec[i];
                ((SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern)).RemoveFromSelection();
            }
#else
            foreach (AutomationElement element in aec)
            {
                ((SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern)).RemoveFromSelection();
            }
#endif

            Comment("After removing selection, there are  " + aec.Count + " items selected");

            m_TestStep++;
        }
 /// <summary>
 /// 指定したAccessKey属性に一致するAutomationElementを返します
 /// </summary>
 /// <param name="rootElement"></param>
 /// <param name="acckey"></param>
 /// <returns></returns>
 private static IEnumerable<AutomationElement> FindElementsByAccKey(AutomationElement rootElement, string acckey)
 {
     return rootElement.FindAll(
         TreeScope.Element | TreeScope.Descendants,
         new PropertyCondition(AutomationElement.AccessKeyProperty, acckey))
         .Cast<AutomationElement>();
 }
Beispiel #19
0
        private bool SwitchTab(AutomationElement tabControl, int tabIndex)
        {
            // Get a collection of tab pages
            AutomationElementCollection aeTabItems = tabControl.FindAll(TreeScope.Descendants,
                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem));

            if (!(tabIndex < aeTabItems.Count))
                return false;

            // Set focus to the Listen tab
            AutomationElement aeListenTab = aeTabItems[tabIndex];
            aeListenTab.SetFocus();

            return true;
        }
Beispiel #20
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        void TS_ChangeListValueRandom(AutomationElement element, WaitTestState callBackForChange, CheckType checkType)
        {
            Library.ValidateArgumentNonNull(element, "element");

            AutomationElementCollection elements = element.FindAll(TreeScope.Descendants,
                new AndCondition(
                new Condition[]
                {
                    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem),
                    new PropertyCondition(SelectionItemPattern.IsSelectedProperty, false)
                }));

            if (elements.Count != 0)
            {

                Random rnd = new Random();
                AutomationElement newSelect = elements[rnd.Next(elements.Count)];

                if (newSelect == null)
                    ThrowMe(checkType, "Could not get a non selected item");

                _changedToValue = newSelect.Current.Name;

                SelectionItemPattern sip = newSelect.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                sip.Select();

                Wait(callBackForChange, _WAIT_NORMAL_MILLISECONDS, checkType);
            }
            m_TestStep++;
        }
Beispiel #21
0
        /// <summary>
        /// Exract items from parent window by Control Type
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="className"></param>
        /// <returns></returns>
        public static AutomationElementCollection ExtractElementByControlType(AutomationElement parent, ControlType type)
        {
            ValidateArgumentNotNull(parent, "Extract Control from parent window by Control Type, parent ");
            Condition condition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);
            AutomationElementCollection appElement;
            DateTime timeOut = DateTime.Now.AddMilliseconds(TimeOutMillSec);
            do
            {
                appElement = parent.FindAll(TreeScope.Descendants, condition);
            } while (appElement == null && DateTime.Now < timeOut);

            return appElement;
        }
        //**************************************************************************************************************************************************************

        public static void UIA_SetFocusOfFirstTextBox(AutomationElement uiaWindow, Window window)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);
            try
            {
                PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text);
                AutomationElementCollection textBoxes = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
                foreach (AutomationElement textBox in textBoxes)
                {
                    TestStack.White.UIItems.TextBox t = new TestStack.White.UIItems.TextBox(textBox, window.ActionListener);
                    t.Focus();
                    t.Click();
                    Thread.Sleep(int.Parse(Execution_Speed));
                    break;
                }
                Logger.logMessage("UIA_SetFocusOfFirstTextBox " + uiaWindow + "->" + window + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

            }
            catch (Exception e)
            {
                Logger.logMessage("UIA_SetFocusOfFirstTextBox " + uiaWindow + "->" + window + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
        private ArrayList getAutomationElementsWithFindAll(
            AutomationElement element,
            string name,
            string automationId,
            string className,
            string textValue,
            string[] controlType,
            AndCondition conditions,
            bool caseSensitive,
            bool onlyOneResult,
            bool onlyTopLevel)
        {
            ArrayList resultCollection = new ArrayList();

            try {

                AutomationElementCollection results =
                    element.FindAll(
                        TreeScope.Descendants,
                        conditions);
                this.WriteVerbose(
                    this,
                    "There are roughly " +
                    results.Count.ToString() +
                    " elements");

                resultCollection =
                    returnOnlyRightElements(
                        results,
                        name,
                        automationId,
                        className,
                        textValue,
                        controlType,
                        caseSensitive);

            }
            catch { //(Exception eWildCardSearch) {

            }

            return resultCollection;
        }
        /// -------------------------------------------------------------------
        /// <summary>
        /// Determine what will expand the element, and then expand it using
        /// the keystroke
        /// </summary>
        /// -------------------------------------------------------------------
        private void TS_ExpandUsingMouseLeftClick(AutomationElement element, CheckType checkType)
        {
            AutomationElement dropDown;
            switch (m_le.Current.ControlType.ProgrammaticName)
            {
                case "ControlType.ComboBox":
                    {
                        // Assume combo boxes have one and only one drop down button
                        // at the child level of the combo box
                        AutomationElementCollection buttons = element.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
                        if (buttons.Count != 1)
                            ThrowMe(checkType, "There are two buttons, not sure which one will expand the combo box");

                        dropDown = buttons[0];

                        break;
                    }
                default:
                    {
                        dropDown = element;
                        break;
                    }
            }

            TS_SendLeftMouseClick(dropDown, CheckType.IncorrectElementConfiguration);

            // m_TestStep++ this is done in TS_SendLeftMouseClick above, so don't 
            // duplicate the addition here.
        }
        //**************************************************************************************************************************************************************


        public static void UIA_SetTextByAutomationID(AutomationElement uiaWindow, Window window, string automationID, string value)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);
            try
            {
                PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit);
                AutomationElementCollection textBoxes = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
                foreach (AutomationElement e in textBoxes)
                {
                    if (e.Current.AutomationId.Equals(automationID))
                    {
                        TestStack.White.UIItems.TextBox t = new TestStack.White.UIItems.TextBox(e, window.ActionListener);
                        t.Text = value;
                    }
                }
                Thread.Sleep(int.Parse(Execution_Speed));
                Logger.logMessage("UIA_SetTextByAutomationID " + uiaWindow + "->" + window + "->" + automationID + "->" + value + "->" + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

            }
            catch (Exception e)
            {
                Logger.logMessage("UIA_SetTextByAutomationID " + uiaWindow + "->" + window + "->" + automationID + "->" + value + "->" + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
Beispiel #26
0
 //根据NameProperty获取元素数组
 public static AutomationElementCollection FindElementCollectionByControlType(AutomationElement appForm, ControlType controlType)
 {
     AutomationElementCollection tarFindElement = appForm.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, controlType));
     return tarFindElement;
 }
        //**************************************************************************************************************************************************************

        public static AutomationElement UIA_GetChildWindow(AutomationElement appWindow, string childWindowName)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);
            AutomationElement childWindow = null;

            try
            {
                PropertyCondition windowTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
                PropertyCondition windowNameCondition = new PropertyCondition(AutomationElement.NameProperty, childWindowName);
                AndCondition windowCondition = new AndCondition(windowTypeCondition, windowNameCondition);
                AutomationElement window = appWindow.FindFirst(TreeScope.Children, windowCondition);

                AutomationElementCollection windows = appWindow.FindAll(TreeScope.Descendants, windowTypeCondition);

                foreach (AutomationElement w in windows)
                {
                    if (w.Current.Name.Equals(childWindowName) || w.Current.Name.Contains(childWindowName))
                    {
                        childWindow = w;
                        break;
                    }
                }
                Logger.logMessage("UIA_GetChildWindow " + appWindow + "->" + childWindowName + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

                return childWindow;
            }
            catch (Exception e)
            {
                Logger.logMessage("UIA_GetChildWindow " + appWindow + "->" + childWindowName + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
Beispiel #28
0
 public static void TextPatternRangeFromChildBad(AutomationElement element)
 {
     object patternObj = null;
     if (GetPatternObject(element, TextPattern.Pattern, ref patternObj))
     {
         TextPattern pattern = (TextPattern)patternObj;
         Dump("TextPattern.RangeFromChild(bad)", true, element);
         try
         {
             AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, Condition.TrueCondition);
             object property = pattern.RangeFromChild(TreeWalker.RawViewWalker.GetParent(element));
         }
         catch (Exception exception)
         {
             VerifyException(element, exception,
                 typeof(ElementNotAvailableException),
                 typeof(InvalidOperationException),      /* {"Win32 Edit controls don't have children."} */
                 typeof(ArgumentException)               /* {"Value does not fall within the expected range."} */
                 );
         }
     }
 }
        //**************************************************************************************************************************************************************


        public static void UIA_ClickOnPaneItem(AutomationElement uiaWindow, Window window, int index)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);

            try
            {
                PropertyCondition paneCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane);
                AutomationElementCollection allPanes = uiaWindow.FindAll(TreeScope.Descendants, paneCondition);

                TestStack.White.UIItems.Panel p = new TestStack.White.UIItems.Panel(allPanes[index], window.ActionListener);
                p.Focus();
                p.Click();
                Thread.Sleep(int.Parse(Execution_Speed));
                Logger.logMessage("UIA_ClickOnPaneItem " + uiaWindow + "->" + window + "->" + index + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

            }
            catch (Exception e)
            {
                Logger.logMessage("UIA_ClickOnPaneItem " + uiaWindow + "->" + window + "->" + index + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
Beispiel #30
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TS_GetRandomSelectableItem(AutomationElement selectionContainer, out AutomationElement element, bool selectedState, CheckType checkType)
        {
            Comment("Calling LibraryGetSelectionItems()");

            element = null;
            AutomationElement element2 = null; ;

            AutomationElementCollection IsSelected;

            if (selectionContainer.Current.ControlType == ControlType.Calendar)
            {
                IsSelected = selectionContainer.FindAll(TreeScope.Descendants, new PropertyCondition(SelectionItemPattern.IsSelectedProperty, true));

                if (IsSelected.Count > 0)
                {
                    switch (selectedState)
                    {
                        case true:  // Find something that is selected
                            {
                                // Return the 1st or last element since you can only remove exterior elements from selection
								element = IsSelected[(bool)Helpers.RandomValue(true, true) == true ? 0 : IsSelected.Count - 1];
                                break;
                            }

                        case false: // Find something that is not selected yet
                            {
								switch ((bool)Helpers.RandomValue(true, true))
                                {
                                    case true:  // Looking for something at the beginning of the selection
                                        element2 = TreeWalker.RawViewWalker.GetPreviousSibling(IsSelected[0]);

                                        // If we are at the start, get something from the tail
                                        if (element2 == null)
                                        {
                                            element2 = TreeWalker.RawViewWalker.GetNextSibling(IsSelected[IsSelected.Count - 1]);
                                        }

                                        // If for some reason they are all selected, then error out
                                        if (element2 == null)
                                            ThrowMe(checkType, "Could not get any element that was unselected");

                                        break;
                                    case false: // Looking for something at the end of the selection
                                        element2 = TreeWalker.RawViewWalker.GetNextSibling(IsSelected[IsSelected.Count - 1]);

                                        // If we are at the end, get something from the start
                                        if (element2 == null)
                                        {
                                            element2 = TreeWalker.RawViewWalker.GetPreviousSibling(IsSelected[0]);
                                        }

                                        // If for some reason they are all selected, then error out
                                        if (element2 == null)
                                            ThrowMe(checkType, "Could not get any element that was unselected");

                                        break;
                                }

                                element = element2;

                                break;
                            }
                    }
                }
            }
            else
            {

                Condition condition = new AndCondition
                    (
                    new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true),
                    new PropertyCondition(SelectionItemPattern.IsSelectedProperty, selectedState)
                    );

                IsSelected = selectionContainer.FindAll(TreeScope.Descendants, condition);

                if (IsSelected.Count > 0)
                {   // Return any element
					element = IsSelected[(int)Helpers.RandomValue(0, IsSelected.Count - 1)];
                }
            }

            if (element == null)
                ThrowMe(checkType, "Could not find element who's SelectionItemPattern.IsSelected = " + selectedState);

            Comment("Found AutomationElement(" + Library.GetUISpyLook(element) + ")");
            m_TestStep++;

        }
Beispiel #31
0
        //**************************************************************************************************************************************************************
        public static void UIA_ClickOnPaneItem(AutomationElement uiaWindow, Window window, int index)
        {
            try
            {
                PropertyCondition paneCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane);
                AutomationElementCollection allPanes = uiaWindow.FindAll(TreeScope.Descendants, paneCondition);

                TestStack.White.UIItems.Panel p = new TestStack.White.UIItems.Panel(allPanes[index], window.ActionListener);
                p.Focus();
                p.Click();
                Thread.Sleep(int.Parse(Execution_Speed));
            }
            catch (Exception e)
            {
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }