protected override void DoImpl()
        {
            var element = GetFrameworkElementParent <ListBoxItem>();

            if (element == null)
            {
                SendNotFoundResult(string.Format("ListBoxItemScrollIntoViewCommand: Could not find element : {0}",
                                                 AutomationIdentifier.ToIdOrName()));
                return;
            }

            element.InvokeAutomationPeer <ListBoxItem, IScrollItemProvider>(PatternInterface.Selection,
                                                                            (pattern) =>
            {
                try
                {
                    pattern.ScrollIntoView();
                }
                catch (Exception exception)
                {
                    throw new TestAutomationException
                        ("Exception while invoking list box select pattern",
                        exception);
                }
            });
        }
        protected override void DoImpl()
        {
            var element = GetFrameworkElement();

            if (element == null)
            {
                element =
                    (FrameworkElement)
                    AutomationElementFinder.FindElementByDisplayedText(AutomationIdentifier.AutomationName);
            }

            if (element != null)
            {
                //Find out its background color
                if (element is Border)
                {
                    var elementControl = (Border)element;

                    if (elementControl.Background is SolidColorBrush)
                    {
                        SendColorResult(((SolidColorBrush)elementControl.Background).Color.ToString());
                        return;
                    }
                }
            }

            SendNotFoundResult(string.Format("GetColorCommand: Could not find the element - {0}",
                                             AutomationIdentifier.ToIdOrName()));
        }
Exemple #3
0
        protected override void DoImpl()
        {
            var element = GetFrameworkElement();

            if (element == null)
            {
                return;
            }

            string textValue;

            if (ValueCommandHelper.TryGetValue(element, out textValue))
            {
                SendTextResult(textValue);
                return;
            }

            var value = AutomationElementFinder.GetValueForFrameworkElement(element);

            if (value != null)
            {
                SendTextResult(value);
                return;
            }

            // if text is missing... then give up
            SendNotFoundResult(string.Format("GetValueCommand: Could not find the element : {0}",
                                             AutomationIdentifier.ToIdOrName()));
        }
Exemple #4
0
        protected override void DoImpl()
        {
            var element = GetUIElement();

            if (element == null)
            {
                return;
            }

            if (AutomationElementFinder.SetElementProperty(element, "Text", Text))
            {
                SendSuccessResult();
                return;
            }

            if (AutomationElementFinder.SetElementProperty(element, "Password", Text))
            {
                SendSuccessResult();
                return;
            }

            if (AutomationElementFinder.SetElementProperty <object>(element, "Content", Text))
            {
                SendSuccessResult();
                return;
            }

            // if text, password and content are all missing... then give up
            SendNotFoundResult(string.Format("SetTextCommand: Could not set text :{0} for control :{1}", Text,
                                             AutomationIdentifier.ToIdOrName()));
        }
        protected UIElement GetUIElement(bool sendNotFoundResultOnFail = true)
        {
            var element = AutomationElementFinder.FindElement(AutomationIdentifier, Ordinal, ParentIdentifier);

            if (element == null)
            {
                if (sendNotFoundResultOnFail)
                {
                    SendNotFoundResult(string.Format("GetUIElement: Could not find - {0}",
                                                     AutomationIdentifier.ToIdOrName()));
                }
                return(null);
            }

            return(element);
        }
        protected FrameworkElement GetFrameworkElementParent <TParentType>(bool sendNotFoundResultOnFail = true)
            where TParentType : FrameworkElement
        {
            var element =
                AutomationElementFinder.FindElementsNearestParentOfType <TParentType>(
                    AutomationElementFinder.GetRootVisual(), AutomationIdentifier) as FrameworkElement;

            if (element == null)
            {
                if (sendNotFoundResultOnFail)
                {
                    SendNotFoundResult(string.Format("GetFrameworkElement<{0}>: Could not find - {1}",
                                                     typeof(TParentType), AutomationIdentifier.ToIdOrName()));
                }
                return(null);
            }

            return(element);
        }
        protected override void DoImpl()
        {
            var element = GetFrameworkElement();

            if (element == null)
            {
                return;
            }

            var control = element as Control;

            if (control == null)
            {
                SendNotFoundResult(string.Format("SetFocusCommand: Could not find the control : {0}",
                                                 AutomationIdentifier.ToIdOrName()));
                return;
            }

            control.Focus();
            SendSuccessResult();
        }
Exemple #8
0
        protected override void DoImpl()
        {
            var element = GetFrameworkElement();

            if (element == null)
            {
                return;
            }

            var text = AutomationElementFinder.GetTextForFrameworkElement(element);

            if (text != null)
            {
                SendTextResult(text);
                return;
            }

            // if text is missing... then give up
            SendNotFoundResult(string.Format("GetTextCommand: Could not find the element : {0}",
                                             AutomationIdentifier.ToIdOrName()));
        }
Exemple #9
0
        protected override void DoImpl()
        {
            var element = GetFrameworkElement();

            if (element == null)
            {
                SendNotFoundResult(
                    string.Format(
                        "GetIsEnabledCommand: Could not find the control - {0}",
                        AutomationIdentifier.ToIdOrName()));
                return;
            }

            var control = element as Control;

            if (control == null)
            {
                SendNotFoundResult(string.Format("GetIsEnabledCommand: Could not find the control - {0}", AutomationIdentifier.ToIdOrName()));
                return;
            }

            SendTextResult(control.IsEnabled.ToString());
        }
Exemple #10
0
        protected override void DoImpl()
        {
            var element = GetFrameworkElement(false);

            if (element == null)
            {
                SendNotFoundResult(string.Format("PivotCommand: Could not find the element : {0}",
                                                 AutomationIdentifier.ToIdOrName()));
                return;
            }

            var pivot = element as Pivot;

            if (pivot != null)
            {
                if (MovePivot(pivot))
                {
                    SendSuccessResult();
                }
            }
            else
            {
                var pano = element as Panorama;

                if (pano != null)
                {
                    if (MovePano(pano))
                    {
                        SendSuccessResult();
                    }
                }
                else
                {
                    SendNotFoundResult("PivotCommand: Could not find the Panorama");
                }
            }
        }
        protected override void DoImpl()
        {
            var element = GetFrameworkElement(false);

            if (element == null)
            {
                SendNotFoundResult(string.Format("ToggleButtonCommand: Could not find the element : {0}",
                                                 AutomationIdentifier.ToIdOrName()));
                return;
            }

            var peer = FrameworkElementAutomationPeer.CreatePeerForElement(element);

            if (peer == null)
            {
                SendNotFoundResult("Couldn't find automation peer.");
            }

            var pattern = peer.GetPattern(PatternInterface.Toggle) as IToggleProvider;

            if (pattern == null)
            {
                SendNotFoundResult();
            }

            pattern.Toggle();

            var buttonBase = element as ButtonBase;

            // Execute the bound command, if available, because IToggleProvider doesn't trigger that.
            if (buttonBase != null && buttonBase.Command != null)
            {
                buttonBase.Command.Execute(buttonBase.CommandParameter);
            }

            SendSuccessResult();
        }
Exemple #12
0
        protected override void DoImpl()
        {
            var element = GetUIElement();

            if (element == null)
            {
                return;
            }

            if (ValueCommandHelper.TrySetValue(element, TextValue))
            {
                SendSuccessResult();
                return;
            }

            if (AutomationElementFinder.SetElementProperty(element, "Text", TextValue))
            {
                SendSuccessResult();
                return;
            }

            if (AutomationElementFinder.SetElementProperty(element, "Password", TextValue))
            {
                SendSuccessResult();
                return;
            }

            bool boolValue;

            if (bool.TryParse(TextValue, out boolValue))
            {
                if (AutomationElementFinder.SetElementProperty(element, "IsChecked", boolValue))
                {
                    SendSuccessResult();
                    return;
                }
            }

            int intValue;

            if (int.TryParse(TextValue, out intValue))
            {
                if (AutomationElementFinder.SetElementProperty(element, "Value", intValue))
                {
                    SendSuccessResult();
                    return;
                }
            }

            double doubleValue;

            if (double.TryParse(TextValue, out doubleValue))
            {
                if (AutomationElementFinder.SetElementProperty(element, "Value", doubleValue))
                {
                    SendSuccessResult();
                    return;
                }
            }

            DateTime dateTimeValue;

            if (DateTime.TryParse(TextValue, out dateTimeValue))
            {
                if (AutomationElementFinder.SetElementProperty(element, "Value", dateTimeValue))
                {
                    SendSuccessResult();
                    return;
                }

                if (AutomationElementFinder.SetElementProperty <DateTime?>(element, "Value", dateTimeValue))
                {
                    SendSuccessResult();
                    return;
                }
            }

            if (AutomationElementFinder.SetElementProperty(element, "Value", TextValue))
            {
                SendSuccessResult();
                return;
            }


            // if text, password IsChecked, Value are all missing... then give up
            SendNotFoundResult(string.Format("SetValueCommand: Could not set the value :{0} in control :{1}", TextValue,
                                             AutomationIdentifier.ToIdOrName()));
        }
        protected override void DoImpl()
        {
            var element = GetFrameworkElement();
            var selector = element as Selector;
            if (selector == null)
            {
                return;
            }

            var item = selector.Items[IndexOfItemToSelect];

            var identifier = new AutomationIdentifier {DisplayedText = item.ToString()};
            var listBoxItem = AutomationElementFinder.FindElement(identifier);
            if (listBoxItem == null)
            {
                SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the list box item element : {0}",
                                                 identifier.ToIdOrName()));
                return;
            }

            var button = AutomationElementFinder.FindElementsChildByType<Button>(listBoxItem);
            if (button != null)  // Workaround for nasty lists that use buttons instead of the list select method
            {
                // automate the invoke
                var buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(button);
                var pattern = buttonPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                if (pattern == null)
                {
                    SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the invoke pattern : {0}",
                                                     identifier.ToIdOrName()));
                    return;
                }

                try
                {
                    pattern.Invoke();
                }
                catch (Exception exception)
                {
                    SendExceptionFailedResult(exception);
                }

            }
            else
            {

                // automate the select
                var listBoxPeer = FrameworkElementAutomationPeer.CreatePeerForElement(listBoxItem);
                var pattern = listBoxPeer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider;
                if (pattern == null)
                {
                    SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the select pattern : {0}",
                                                     identifier.ToIdOrName()));
                    return;
                }

                try
                {
                    pattern.Select();
                }
                catch (Exception exception)
                {
                    SendExceptionFailedResult(exception);
                }
            }
            SendSuccessResult();
        }
Exemple #14
0
        protected override void DoImpl()
        {
            var element  = GetFrameworkElement();
            var selector = element as Selector;

            if (selector == null)
            {
                return;
            }

            var item = selector.Items[IndexOfItemToSelect];

            var identifier = new AutomationIdentifier {
                DisplayedText = item.ToString()
            };
            var listBoxItem = AutomationElementFinder.FindElement(identifier);

            if (listBoxItem == null)
            {
                SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the list box item element : {0}",
                                                 identifier.ToIdOrName()));
                return;
            }

            var button = AutomationElementFinder.FindElementsChildByType <Button>(listBoxItem);

            if (button != null) // Workaround for nasty lists that use buttons instead of the list select method
            {
                // automate the invoke
                var buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(button);
                var pattern    = buttonPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                if (pattern == null)
                {
                    SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the invoke pattern : {0}",
                                                     identifier.ToIdOrName()));
                    return;
                }

                try
                {
                    pattern.Invoke();
                }
                catch (Exception exception)
                {
                    SendExceptionFailedResult(exception);
                }
            }
            else
            {
                // automate the select
                var listBoxPeer = FrameworkElementAutomationPeer.CreatePeerForElement(listBoxItem);
                var pattern     = listBoxPeer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider;
                if (pattern == null)
                {
                    SendNotFoundResult(string.Format("SelectorItemCommand: Could not find the select pattern : {0}",
                                                     identifier.ToIdOrName()));
                    return;
                }

                try
                {
                    pattern.Select();
                }
                catch (Exception exception)
                {
                    SendExceptionFailedResult(exception);
                }
            }
            SendSuccessResult();
        }