コード例 #1
0
ファイル: uiaworker.cs プロジェクト: sbillah/GeneralUtility
        ///--------------------------------------------------------------------
        /// <summary>
        /// Retrieve the parent and grandparent of the current element.
        /// </summary>
        /// <param name="element">The element of interest.</param>
        /// <param name="eventStore">
        /// The UI Automation event storage class.
        /// </param>
        ///--------------------------------------------------------------------
        private void GetAncestors(
            AutomationElement element, UiaEventRecord eventStore)
        {
            AutomationElement parent =
                TreeWalker.ControlViewWalker.GetParent(element);

            if (parent != null)
            {
                eventStore.Parent = parent.Current.AutomationId;
                AutomationElement grandparent =
                    TreeWalker.ControlViewWalker.GetParent(parent);
                if (grandparent != null)
                {
                    eventStore.Grandparent = grandparent.Current.AutomationId;
                }
            }
        }
コード例 #2
0
ファイル: uiaworker.cs プロジェクト: sbillah/GeneralUtility
        ///--------------------------------------------------------------------
        /// <summary>
        /// Store the element information for later script generation.
        /// </summary>
        /// <param name="element">The element of interest.</param>
        /// <param name="e">The event of interest.</param>
        /// <param name="scriptAction">
        /// The pre-defined function to call in the generated script.
        /// </param>
        /// <remarks>
        /// Note that the generated script will have function calls in the same
        /// order as the event timestamps stored here. Since there is
        /// no way to ensure the order of events, the tester may have to
        /// rearrange the function calls in the script so controls are enabled
        /// as necessary. This behavior can be evident with interdependent
        /// controls that get focus and perform an action such as the controls in
        /// the target application.
        /// </remarks>
        ///--------------------------------------------------------------------
        private void StoreElement(
            AutomationElement element, AutomationEvent e, string scriptAction)
        {
            DateTime       time       = DateTime.Now;
            UiaEventRecord eventStore = new UiaEventRecord();

            try
            {
                eventStore.AutomationId = element.Cached.AutomationId;
                eventStore.ClassName    = element.Cached.ClassName;
                eventStore.ControlType  =
                    element.Cached.ControlType.ProgrammaticName;
                eventStore.EventId      = e.ProgrammaticName;
                eventStore.ScriptAction = scriptAction;
                GetAncestors(element, eventStore);
                eventStore.SupportedPatterns = element.GetSupportedPatterns();
                eventStore.EventTime         = time;
                elementQueue.Enqueue(eventStore);
            }
            catch (NullReferenceException)
            {
                return;
            }
        }