Пример #1
0
        /// <summary>
        /// Finds the requested element from its Automation ID and sets text in it,
        /// throwing an assert if the element returned is null.
        /// </summary>
        /// <param name="parent">The parent under which the element we're searching for lives.</param>
        /// <param name="automationID">The automation ID to search for under the parent</param>
        public static void FindAndSetText(AutomationElement parent, string automationID, string text)
        {
            AutomationElement element = AutomationHelper.FindDescendantById(parent, automationID);

            TestServices.Assert(element != null, "Could not find the element with Automation ID '"
                                + automationID + "'");
            AutomationHelper.SetText(element, text);
        }
Пример #2
0
        /// <summary>
        /// Finds the requested element from its Automation ID and invokes it,
        /// throwing an assert if the element returned is null.
        /// </summary>
        /// <param name="parent">The parent under which the element we're searching for lives.</param>
        /// <param name="automationID">The automation ID to search for under the parent</param>
        public static void FindAndInvoke(AutomationElement parent, string automationID)
        {
            //Find the element
            AutomationElement element = AutomationHelper.FindDescendantById(parent, automationID);

            TestServices.Assert(element != null, "Could not find the element with Automation ID '"
                                + automationID + "'");

            //Invoke the element
            AutomationHelper.Invoke(element);
        }
Пример #3
0
        /// <summary>
        /// Similar to FindAndInvoke, with the difference that this method
        /// performs a "manual" (non-input pattern) invocation of the element to work around
        /// automation issues with modal dialogs.
        /// </summary>
        /// <param name="parent">The parent under which the element we're searching for lives.</param>
        /// <param name="automationID">The automation ID to search for under the parent</param>
        /// <param name="failSilently">If true, we will simply return if the element can't be
        /// found or can't be focused.  If false, we throw an exception.</param>
        public static void FindAndManualInvoke(
            AutomationElement parent, string automationID, bool failSilently)
        {
            //We do the invoke differently here due to an unfortunate issue where
            //Invoke()ing a Winforms Button that brings up a Modal Dialog
            //will not return until the Modal Dialog is closed.
            //This obviously would prevent this test from continuing on past that point.
            //What we're doing to work around the issue is to put focus on the button and invoke
            //an Enter keypress to bring up the dialog.
            AutomationElement element = AutomationHelper.FindDescendantById(
                parent, automationID, !failSilently);

            if (failSilently && (element == null))
            {
                TestServices.Log("warning - FindAndManualInvoke could not locate " + automationID);
                return;
            }
            TestServices.Assert(element != null, "Could not find the element with Automation ID '"
                                + automationID + "'");

            //Focus the element
            try
            {
                element.SetFocus();
            }
            catch (InvalidOperationException)
            {
                if (failSilently)
                {
                    TestServices.Log("warning - FindAndManualInvoke could not focus " + automationID);
                    return;
                }
                else
                {
                    throw;
                }
            }

            //Ensure the element has focus before continuing.
            WaitForFocus(element);

            //Invoke the "Enter" key to raise the dialog
            Input.SendKeyboardInput(Key.Enter, true);
            WaitForUIRefresh();
            Input.SendKeyboardInput(Key.Enter, false);
        }
Пример #4
0
        /// <summary>
        /// Waits for the address bar in a given IE window to display the
        /// specified address.
        /// </summary>
        /// <remarks>
        /// Will TestServices.Assert on timeout.
        /// </remarks>
        /// <param name="ieWindow">The IE window</param>
        /// <param name="address">The address to wait for</param>
        public static void WaitForAddressBarText(AutomationElement ieWindow, string address)
        {
            // wait for the address bar to show the new document
            AutomationElement addressBar = AutomationHelper.FindDescendantById(ieWindow, "41477");

            Condition editClassCondition = new PropertyCondition(AutomationElement.ClassNameProperty, "Edit");

            addressBar = addressBar.FindFirst(TreeScope.Descendants, editClassCondition);

            TestServices.Assert(
                addressBar != null,
                "Address bar edit control was not found.");

            TraceAutomationElement("AddressBar", addressBar);

            DateTime end          = DateTime.Now.AddMilliseconds(Timeout);
            bool     foundAddress = false;

            while ((!foundAddress) && (DateTime.Now < end))
            {
                TextPattern textPattern    = (TextPattern)(addressBar.GetCurrentPattern(TextPattern.Pattern));
                string      currentAddress = textPattern.DocumentRange.GetText(-1);

                if (currentAddress.Equals(address, StringComparison.CurrentCultureIgnoreCase))
                {
                    foundAddress = true;
                    break;
                }
                else
                {
                    System.Threading.Thread.Sleep(Interval);
                }
            }

            TestServices.Assert(
                foundAddress,
                "The address was not found: {0}",
                address);
        }