コード例 #1
0
ファイル: UIAActionManager.cs プロジェクト: yhtsnda/dotnetabt
        /// <summary>
        /// given a criteria, find a control within a window
        /// </summary>
        /// <param name="window">the containing window</param>
        /// <param name="criteria">the criteria to find the control</param>
        /// <returns>the found control. null - if not found</returns>
        public IUIItem FindControl(Window window, Dictionary <string, string> criteria)
        {
            // the "all" condition
            SearchCriteria crit = SearchCriteria.All;

            // for each criteria, AND with a new condition
            foreach (string key in criteria.Keys)
            {
                switch (key.ToLower())
                {
                case Constants.PropertyNames.ControlType:
                    crit = crit.AndControlType(GetTypeByName(criteria[key]));
                    break;

                case Constants.PropertyNames.AutomationId:
                    crit = crit.AndAutomationId(criteria[key]);
                    break;

                case Constants.PropertyNames.Text:
                    crit = crit.AndByText(criteria[key]);
                    break;

                default:
                    return(null);
                }
                ;
            }

            // search for control with 'crit'
            IUIItem item = window.Get(crit, WaitTime);

            // return the found control
            return(item);
        }
コード例 #2
0
        static void test2()
        {
            Application app    = Application.Attach("CnEport.SuperPass.UIModule.Eport");
            Window      window = app.GetWindow(SearchCriteria.ByAutomationId("AppForm"), InitializeOption.NoCache);

            SearchCriteria searchGName = SearchCriteria.ByClassName("WindowsForms10.EDIT.app.0.202c666");

            searchGName.AndControlType(typeof(TextBox), WindowsFramework.WinForms);
            //searchGName.AndAutomationId("GName");
            //searchGName.AndByText("规格型号");
            StringBuilder sb = new StringBuilder();

            foreach (TextBox a in window.GetMultiple(searchGName))
            {
                sb.AppendFormat("name:{0} id:{1} helpText:{2}\n", a.Name, a.Id, a.HelpText);
                if (a.HelpText.IndexOf("规格型号") > -1)
                {
                    a.Text = "testtest";
                }
            }
            System.IO.File.WriteAllText("textbox.txt", sb.ToString());
        }
コード例 #3
0
        static void test1()
        {
            ProcessStartInfo process = new ProcessStartInfo(@"WindowsFormsApplication1.exe");
            Application      app     = Application.AttachOrLaunch(process);
            Window           window  = app.GetWindow("Form1", InitializeOption.NoCache);

            SearchCriteria textSearch = SearchCriteria.ByClassName("WindowsForms10.EDIT.app.0.2bf8098_r16_ad1");

            textSearch.AndControlType(typeof(TextBox), WindowsFramework.WinForms);
            textSearch.AndAutomationId("textbox1");
            TextBox textBox1 = window.Get <TextBox>();

            textBox1.Text = "hello qblong";

            SearchCriteria btnSearch = SearchCriteria.ByClassName("WindowsForms10.BUTTON.app.0.2bf8098_r16_ad1");

            btnSearch.AndControlType(typeof(Button), WindowsFramework.WinForms);
            btnSearch.AndAutomationId("button1");
            Button button = window.Get <Button>(btnSearch);

            button.Click();
        }
コード例 #4
0
        public static T CustomGet <T>(this IUIItem item, SearchCriteria searchCriteria = null, TimeSpan?retryInterval = null, TimeSpan?timeout = null, bool throwsException = true)
            where T : IUIItem
        {
            searchCriteria = searchCriteria ?? SearchCriteria.All;
            timeout        = timeout ?? TimeSpan.FromMilliseconds(DefaultTimeoutMs);
            retryInterval  = retryInterval ?? TimeSpan.FromMilliseconds(DefaultRetryIntervalMs);
            DateTime startTime = DateTime.Now;

            searchCriteria = searchCriteria.AndControlType(typeof(T), item.Framework);
            UIItemContainer container = new UIItemContainer(item.AutomationElement, item.ActionListener);

            while (true)
            {
                try
                {
                    IUIItem element = container.Get(searchCriteria, TimeSpan.Zero);
                    if (element == null)
                    {
                        throw new Exception("Null element found while getting " + searchCriteria);
                    }
                    return((T)element);
                }
                catch (AutomationException)
                {
                    TimeSpan elapsedTime     = DateTime.Now.Subtract(startTime);
                    bool     timeoutOccurred = elapsedTime > timeout;
                    if (timeoutOccurred)
                    {
                        break;
                    }
                    Thread.Sleep((TimeSpan)retryInterval);
                    // gives the automation time to refresh UIAutomation tree
                }
            }
            Assert.False(throwsException, $"Failed to get {searchCriteria} in {container}.");
            return(default(T));
        }
コード例 #5
0
ファイル: WPFUIItem.cs プロジェクト: zeit200/WhiteNetstandard
 /// <summary>
 /// Check if any UI Item of a certain Type exists
 /// </summary>
 /// <typeparam name="T">Type of Item</typeparam>
 /// <param name="uiItem">The root UI Item from were to start searching</param>
 /// <param name="searchCriteria">The Search Criteria to use for the Search</param>
 /// <returns><c>true</c> if there is any; otherwise, <c>false</c>.</returns>
 public static bool Exists <T>(this IUIItem uiItem, SearchCriteria searchCriteria) where T : IUIItem
 {
     return(GetUiItemContainer(uiItem).Exists(searchCriteria.AndControlType(typeof(T), uiItem.Framework)));
 }
コード例 #6
0
 public virtual T Get <T>(SearchCriteria searchCriteria, ActionListener actionListener, UIItemFactory factory) where T : UIItem
 {
     return((T)Get(searchCriteria.AndControlType(typeof(T)), actionListener, factory));
 }
コード例 #7
0
 /// <summary>
 /// Finds UIItem which matches specified type and searchCriteria. Type supplied need not be supplied again in SearchCondition.
 /// e.g. in Get<Button>(SearchCriteria.ByAutomationId("OK").ByControlType(typeof(Button)).Indexed(1) the ByControlType(typeof(Button)) part
 /// is redundant. Look at documentation of SearchCriteria for details on it.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="searchCriteria">Criteria provided to search UIItem</param>
 /// <returns>First items matching the type and criteria</returns>
 public virtual T Get <T>(SearchCriteria searchCriteria) where T : UIItem
 {
     return((T)Get(searchCriteria.AndControlType(typeof(T), Framework)));
 }
コード例 #8
0
ファイル: UIItemContainer.cs プロジェクト: yonglehou/White
 public virtual bool Exists <T>(SearchCriteria searchCriteria) where T : IUIItem
 {
     return(Exists(searchCriteria.AndControlType(typeof(T), Framework)));
 }
コード例 #9
0
ファイル: CachedUIItems.cs プロジェクト: timotei/White
 public virtual T Get <T>(SearchCriteria searchCriteria, IActionListener actionListener, IUIItemFactory factory) where T : UIItem
 {
     return((T)Get(searchCriteria.AndControlType(typeof(T), WindowsFramework.None), actionListener, factory));
 }
コード例 #10
0
        /// <summary>
        /// Implements <see cref="IUIItemContainer.GetMultiple{T}(SearchCriteria)" />
        /// </summary>
        public virtual T[] GetMultiple <T>(SearchCriteria searchCriteria) where T : IUIItem
        {
            var items = GetMultiple(searchCriteria.AndControlType(typeof(T), Framework));

            return(items.Select(item => (T)item).Where(cast => cast != null).ToArray());
        }
コード例 #11
0
ファイル: CachedUIItems.cs プロジェクト: vinaybanavsi/White
 public virtual T Get <T>(SearchCriteria searchCriteria, ActionListener actionListener, UIItemFactory factory) where T : UIItem
 {
     return((T)Get(searchCriteria.AndControlType(typeof(T), new WindowsFramework(Constants.MissingFrameworkId)), actionListener, factory));
 }
コード例 #12
0
        public static T Get <T>(this UIItem uiItem, SearchCriteria searchCriteria) where T : UIItem
        {
            UIItemContainer uiItemContainer = GetUiItemContainer(uiItem);

            return((T)uiItemContainer.Get(searchCriteria.AndControlType(typeof(T))));
        }