Beispiel #1
0
        public TextBoxEntryView(IRawElementProviderSimple provider) : base(provider)
        {
            if (IsTableCell)
            {
                Role = Atk.Role.TableCell;
            }
            else
            {
                Role = Atk.Role.Text;
            }

            if (provider.GetPatternProvider(TextPatternIdentifiers.Pattern.Id) == null &&
                provider.GetPatternProvider(ValuePatternIdentifiers.Pattern.Id) == null)
            {
                throw new ArgumentException("Provider for TextBox should either implement IValue or IText");
            }

            textExpert = TextImplementorFactory.GetImplementor(this, provider);
            if ((int)provider.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id)
                == ControlType.Document.Id)
            {
                multiLine = true;
            }

            editableTextExpert = new EditableTextImplementorHelper(this, this, textExpert);
        }
Beispiel #2
0
        public void ProviderPatternTest()
        {
            Label label = new Label();
            IRawElementProviderSimple provider =
                ProviderFactory.GetProvider(label);

            object rangeValueProvider =
                provider.GetPatternProvider(RangeValuePatternIdentifiers.Pattern.Id);

            Assert.IsNull(rangeValueProvider,
                          "RangeValuePattern should not be supported.");

            object tableItemProvider =
                provider.GetPatternProvider(TableItemPatternIdentifiers.Pattern.Id);

            Assert.IsNull(tableItemProvider,
                          "TableItemPattern should not be supported.");

            object textProvider =
                provider.GetPatternProvider(TextPatternIdentifiers.Pattern.Id);

            Assert.IsNull(textProvider,
                          "TextPattern should not be supported.");

            object valueProvider =
                provider.GetPatternProvider(ValuePatternIdentifiers.Pattern.Id);

            Assert.IsNull(valueProvider,
                          "ValuePattern should not be supported.");
        }
Beispiel #3
0
        public ListItem(IRawElementProviderSimple provider) : base(provider)
        {
            invokeProvider        = (IInvokeProvider)provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);
            selectionItemProvider = (ISelectionItemProvider)provider.GetPatternProvider(SelectionItemPatternIdentifiers.Pattern.Id);
            if (selectionItemProvider == null)
            {
                throw new ArgumentException("ListItem should always implement ISelectionItemProvider");
            }
            toggleProvider = (IToggleProvider)provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id);

            textExpert         = TextImplementorFactory.GetImplementor(this, provider);
            imageExpert        = new ImageImplementorHelper(this);
            actionExpert       = new ActionImplementorHelper();
            editableTextExpert = new EditableTextImplementorHelper(this, this, textExpert);

            // TODO: Localize the name?s
            actionExpert.Add("click", "click", null, DoClick);
            if (toggleProvider != null)
            {
                actionExpert.Add("toggle", "toggle", null, DoToggle);
            }
            if (invokeProvider != null)
            {
                actionExpert.Add("invoke", "invoke", null, DoInvoke);
            }
            Role = (toggleProvider != null? Atk.Role.CheckBox: Atk.Role.ListItem);
        }
Beispiel #4
0
        public SplitContainer(IRawElementProviderSimple provider) : base(provider)
        {
            Role = Atk.Role.SplitPane;
            rangeValueProvider = (IRangeValueProvider)provider.GetPatternProvider(RangeValuePatternIdentifiers.Pattern.Id);
            object o = provider.GetPropertyValue(AutomationElementIdentifiers.OrientationProperty.Id);

            if (o is OrientationType)
            {
                orientation = (OrientationType)o;
            }
            else
            {
                IDockProvider dockProvider = (IDockProvider)provider.GetPatternProvider(DockPatternIdentifiers.Pattern.Id);
                if (dockProvider != null)
                {
                    orientation = (dockProvider.DockPosition == DockPosition.Top || dockProvider.DockPosition == DockPosition.Bottom)?
                                  OrientationType.Horizontal:
                                  OrientationType.Vertical;
                }
                else
                {
                    Log.Warn("SplitContainer: Couldn't get orientation for splitter.  Does not support DockProvider.");
                    orientation = OrientationType.Horizontal;
                }
            }
        }
Beispiel #5
0
        public void ScrollableControlProviderTest()
        {
            Panel panel = new Panel();

            Form.Controls.Add(panel);

            IRawElementProviderSimple provider
                = GetProviderFromControl(panel);

            panel.AutoScrollMinSize = new System.Drawing.Size(5000, 5000);
            panel.AutoScroll        = true;

            IScrollProvider scrollProvider
                = provider.GetPatternProvider(ScrollPatternIdentifiers.Pattern.Id)
                  as IScrollProvider;

            Assert.IsNotNull(scrollProvider,
                             "Does not implement IScrollProvider");

            panel.AutoScrollMinSize = new System.Drawing.Size(50, 50);
            scrollProvider          = provider.GetPatternProvider(
                ScrollPatternIdentifiers.Pattern.Id) as IScrollProvider;
            Assert.IsNull(scrollProvider,
                          "Implements IScrollProvider");
        }
Beispiel #6
0
        public TreeItem(IRawElementProviderSimple provider) : base(provider)
        {
            invokeProvider        = (IInvokeProvider)provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);
            selectionItemProvider = (ISelectionItemProvider)provider.GetPatternProvider(SelectionItemPatternIdentifiers.Pattern.Id);

            expandCollapseProvider = provider.GetPatternProvider(
                ExpandCollapsePatternIdentifiers.Pattern.Id) as IExpandCollapseProvider;

            textExpert   = TextImplementorFactory.GetImplementor(this, provider);
            actionExpert = new ActionImplementorHelper();

            // TODO: Localize the name?s
            actionExpert.Add("click", "click", null, DoClick);
            if (ToggleProvider != null)
            {
                actionExpert.Add("toggle", "toggle", null, DoToggle);
            }
            if (invokeProvider != null)
            {
                actionExpert.Add("invoke", "invoke", null, DoInvoke);
            }

            IRawElementProviderFragment fragment = Provider as IRawElementProviderFragment;

            if (fragment != null && fragment.Navigate(NavigateDirection.FirstChild) != null)
            {
                AddExpandContractAction();
            }

            Role = (ToggleProvider != null? Atk.Role.CheckBox: Atk.Role.TableCell);

            imageExpert        = new ImageImplementorHelper(this);
            editableTextExpert = new EditableTextImplementorHelper(this, this, textExpert);
        }
        public void ProviderPatternTest()
        {
            T menuItem = item;
            IRawElementProviderSimple provider = ProviderFactory.GetProvider(menuItem);

            // Should never support Toggle
            object toggleProvider = provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id);

            Assert.IsNull(toggleProvider);

            // Should never support Selection
            object selectionProvider = provider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id);

            Assert.IsNull(selectionProvider);

            // Should never support SelectionItem
            object selectionItemProvider = provider.GetPatternProvider(SelectionItemPatternIdentifiers.Pattern.Id);

            Assert.IsNull(selectionItemProvider);

            object invokeProvider = provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(invokeProvider);
            Assert.IsTrue(invokeProvider is IInvokeProvider, "IInvokeProvider");
        }
Beispiel #8
0
        public MenuItem(IRawElementProviderSimple provider) : base(provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if ((provider as IRawElementProviderFragment) == null)
            {
                throw new ArgumentException("Provider for ParentMenu should be IRawElementProviderFragment");
            }

            textExpert = TextImplementorFactory.GetImplementor(this, provider);

            Role = Atk.Role.MenuItem;

            string name = (string)provider.GetPropertyValue(AutomationElementIdentifiers.NameProperty.Id);

            if (!String.IsNullOrEmpty(name))
            {
                Name = name;
            }

            invokeProvider = (IInvokeProvider)
                             provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);
            toggleProvider = (IToggleProvider)
                             provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id);
            selectionItemProvider = (ISelectionItemProvider)
                                    provider.GetPatternProvider(SelectionItemPatternIdentifiers.Pattern.Id);
            expandCollapseProvider = (IExpandCollapseProvider)
                                     provider.GetPatternProvider(ExpandCollapsePatternIdentifiers.Pattern.Id);

            actionExpert.Add("click", "click", null, DoClick);
        }
        public static ITextImplementor GetImplementor(Adapter adapter,
                                                      IRawElementProviderSimple prov)
        {
            ITextProvider textProvider
                = prov.GetPatternProvider(TextPatternIdentifiers.Pattern.Id)
                  as ITextProvider;

            if (textProvider != null)
            {
                return(new TextProviderTextImplementor(adapter, textProvider));
            }

            IValueProvider valueProvider
                = prov.GetPatternProvider(ValuePatternIdentifiers.Pattern.Id)
                  as IValueProvider;

            if (valueProvider != null)
            {
                return(new ValueProviderTextImplementor(adapter, valueProvider));
            }

            IRangeValueProvider rangeValueProvider
                = prov.GetPatternProvider(RangeValuePatternIdentifiers.Pattern.Id)
                  as IRangeValueProvider;

            if (rangeValueProvider != null)
            {
                return(new RangeValueProviderTextImplementor(adapter, rangeValueProvider));
            }

            return(new NamePropertyTextImplementor(adapter, prov));
        }
        public void InvokeTest()
        {
            T menuItem = item;
            IRawElementProviderSimple provider       = ProviderFactory.GetProvider(menuItem);
            IInvokeProvider           invokeProvider = (IInvokeProvider)
                                                       provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);

            ToolStripItem   childItem           = menuItem.DropDownItems.Add("testchild");
            var             childItemProvider   = ProviderFactory.GetProvider(childItem);
            IInvokeProvider childInvokeProvider = (IInvokeProvider)
                                                  childItemProvider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);

            bool childItemClicked = false;

            childItem.Click += delegate(object sender, EventArgs e) {
                childItemClicked = true;
            };
            childInvokeProvider.Invoke();
            Assert.IsFalse(childItemClicked,
                           "Should fail when invoking child " +
                           "without first showing parent");

            bool itemClicked = false;

            menuItem.Click += delegate(object sender, EventArgs e) {
                itemClicked = true;
            };

            invokeProvider.Invoke();
            Assert.IsTrue(itemClicked,
                          "Click should fire when button is enabled");
            if (menuItem is ToolStripSplitButton)
            {
                ((IExpandCollapseProvider)provider.GetPatternProvider(ExpandCollapsePatternIdentifiers.Pattern.Id)).Expand();
            }
            childInvokeProvider.Invoke();
            Assert.IsTrue(childItemClicked,
                          "Invoking child should work after first showing parent");

            itemClicked      = false;
            menuItem.Enabled = false;
            try {
                invokeProvider.Invoke();
                Assert.Fail("Expected ElementNotEnabledException");
            } catch (ElementNotEnabledException) {
                // Awesome, this is expected
            } catch (Exception e) {
                Assert.Fail("Expected ElementNotEnabledException, " +
                            "but got exception with message: " +
                            e.Message);
            }
            Assert.IsFalse(itemClicked,
                           "Click should not fire when button is disabled");
        }
Beispiel #11
0
        public Spinner(IRawElementProviderSimple provider) : base(provider)
        {
            Role = Atk.Role.SpinButton;
            rangeValueProvider = (IRangeValueProvider)provider.GetPatternProvider(RangeValuePatternIdentifiers.Pattern.Id);

            editableRange
                = provider.GetPatternProvider(EditableRangePatternIdentifiers.Pattern.Id) as IEditableRangeProvider;

            valueProvider = (IValueProvider)provider.GetPatternProvider(ValuePatternIdentifiers.Pattern.Id);
            textExpert    = TextImplementorFactory.GetImplementor(this, provider);
            oldText       = textExpert.Text;
        }
Beispiel #12
0
        public void ProviderPatternTest()
        {
            DockProviderLabel         label    = new DockProviderLabel();
            IRawElementProviderSimple provider = ProviderFactory.GetProvider(label);

            object dockPattern = provider.GetPatternProvider(DockPatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(dockPattern, "DockPattern.");

            IDockProvider dockProvider = dockPattern as IDockProvider;

            Assert.IsNotNull(dockProvider, "IDockProvider ");

            Assert.AreEqual(provider.HostRawElementProvider, label, "HostRawElementProvider");
            Assert.AreEqual(ProviderOptions.ServerSideProvider, provider.ProviderOptions, "ProviderOptions");

            Assert.AreEqual(DockStyle.Top.ToString(),
                            provider.GetPropertyValue(AutomationElementIdentifiers.NameProperty.Id),
                            "NameProperty");

            dockProvider.SetDockPosition(DockPosition.Right);
            Assert.AreEqual(DockStyle.Right.ToString(),
                            provider.GetPropertyValue(AutomationElementIdentifiers.NameProperty.Id),
                            "NameProperty");
        }
Beispiel #13
0
        public void InvokedEventTest()
        {
            IRawElementProviderSimple provider = GetProvider();

            bridge.ResetEventLists();

            //we cannot do this, there's no PerformClick() API in toolbarButton:
            //toolBarButton.PerformClick ();
            //so we use the provider:
            IInvokeProvider invokeProvider =
                (IInvokeProvider)provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);

            invokeProvider.Invoke();

            Assert.AreEqual(1,
                            bridge.AutomationEvents.Count,
                            "event count");

            AutomationEventTuple eventInfo =
                bridge.AutomationEvents [0];

            Assert.AreEqual(InvokePatternIdentifiers.InvokedEvent,
                            eventInfo.eventId,
                            "event type");
            Assert.AreEqual(provider,
                            eventInfo.provider,
                            "event element");
            Assert.AreEqual(InvokePatternIdentifiers.InvokedEvent,
                            eventInfo.e.EventId,
                            "event args event type");
        }
Beispiel #14
0
 public Slider(IRawElementProviderSimple provider) : base(provider)
 {
     Role = Atk.Role.Slider;
     rangeValueProvider = (IRangeValueProvider)provider.GetPatternProvider(RangeValuePatternIdentifiers.Pattern.Id);
     textExpert         = TextImplementorFactory.GetImplementor(this, provider);
     oldText            = textExpert.Text;
 }
        public void ToggleTest()
        {
            CheckBox checkbox = new CheckBox();
            IRawElementProviderSimple provider       = ProviderFactory.GetProvider(checkbox);
            IToggleProvider           toggleProvider = (IToggleProvider)
                                                       provider.GetPatternProvider(TogglePatternIdentifiers.Pattern.Id);

            // Test two-state toggling
            Assert.AreEqual(CheckState.Unchecked, checkbox.CheckState, "Start two-state Unchecked");
            TestToggleEventWithToggle(toggleProvider, ToggleState.On);
            Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "First two-state toggle: Checked");
            TestToggleEventWithToggle(toggleProvider, ToggleState.Off);
            Assert.AreEqual(CheckState.Unchecked, checkbox.CheckState, "Second two-state toggle: Unchecked");
            TestToggleEventWithToggle(toggleProvider, ToggleState.On);
            Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "Third two-state toggle: Checked");

            checkbox.ThreeState = true;

            // Test three-state toggling
            Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "Start three-state Checked");
            TestToggleEventWithToggle(toggleProvider, ToggleState.Off);
            Assert.AreEqual(CheckState.Unchecked, checkbox.CheckState, "First three-state toggle: Unchecked");
            TestToggleEventWithToggle(toggleProvider, ToggleState.Indeterminate);
            Assert.AreEqual(CheckState.Indeterminate, checkbox.CheckState, "Second three-state toggle: Intermediate");
            TestToggleEventWithToggle(toggleProvider, ToggleState.On);
            Assert.AreEqual(CheckState.Checked, checkbox.CheckState, "Third three-state toggle: Checked");

            checkbox.Enabled = false;

            // Test that an exception is thrown when not enabled
            try {
                toggleProvider.Toggle();
                Assert.Fail("Should throw ElementNotEnabledException");
            } catch (ElementNotEnabledException) { }
        }
        public void AddToSelection()
        {
            if (nodeProvider.TreeNode.TreeView != null &&
                !nodeProvider.TreeNode.TreeView.Enabled)
            {
                throw new ElementNotEnabledException();
            }
            IRawElementProviderSimple treeProvider =
                ProviderFactory.FindProvider(nodeProvider.TreeNode.TreeView);

            if (treeProvider == null)
            {
                return;
            }
            ISelectionProvider treeSelectionProvider = (ISelectionProvider)
                                                       treeProvider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id);

            if (treeSelectionProvider == null)
            {
                return;
            }

            if (!treeSelectionProvider.CanSelectMultiple &&
                treeSelectionProvider.GetSelection().Length > 0)
            {
                throw new InvalidOperationException("Cannot select multiple nodes.");
            }

            Select();
        }
        public void TestGridProvider(IRawElementProviderSimple provider)
        {
            IGridProvider gridProvider = (IGridProvider)
                                         provider.GetPatternProvider(GridPatternIdentifiers.Pattern.Id);

            Assert.AreEqual(daysInWeek, gridProvider.ColumnCount);
            Assert.AreEqual(6, gridProvider.RowCount);

            DateTime date = calendar.GetDisplayRange(false).Start;

            for (int r = 0; r < 6; r++)
            {
                for (int c = 0; c < daysInWeek; c++)
                {
                    IRawElementProviderSimple child
                        = gridProvider.GetItem(r, c);

                    TestProperty(child,
                                 AutomationElementIdentifiers.ControlTypeProperty,
                                 ControlType.ListItem.Id);
                    TestProperty(child,
                                 AutomationElementIdentifiers.NameProperty,
                                 date.Day.ToString());

                    date = date.AddDays(1);
                }
            }
        }
        public void IValueProviderSetValueTest()
        {
            DomainUpDown domainUpDown          = new DomainUpDown();
            IRawElementProviderSimple provider =
                ProviderFactory.GetProvider(domainUpDown);

            IValueProvider valueProvider = (IValueProvider)
                                           provider.GetPatternProvider(ValuePatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(valueProvider,
                             "Not returning ValuePatternIdentifiers.");

            try {
                domainUpDown.Enabled = false;
                valueProvider.SetValue("NEW Item");
                Assert.Fail("ElementNotEnabledException not thrown.");
            } catch (ElementNotEnabledException) { }

            domainUpDown.Enabled = true;
            try {
                domainUpDown.ReadOnly = true;
                valueProvider.SetValue("NEW Item");
                Assert.Fail("ElementNotEnabledException not thrown.");
            } catch (ElementNotEnabledException) { }
            domainUpDown.ReadOnly = false;

            string value = "NEW Item";

            valueProvider.SetValue(value);
            domainUpDown.DownButton();
            Assert.AreEqual(value, valueProvider.Value, "SetValue value");
        }
Beispiel #19
0
        public void IGridProviderEventTest()
        {
            StatusStrip statusStrip            = new StatusStrip();
            IRawElementProviderSimple provider =
                ProviderFactory.GetProvider(statusStrip);

            IGridProvider gridProvider = (IGridProvider)
                                         provider.GetPatternProvider(GridPatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(gridProvider,
                             "Not returning GridPatternIdentifiers.");

            bool eventInvoked = false;

            statusStrip.ItemAdded += delegate(object sender, ToolStripItemEventArgs e) {
                eventInvoked = true;
            };
            statusStrip.Items.Add("Item");
            Assert.IsTrue(eventInvoked,
                          "Event should be invoked when items added.");

            eventInvoked             = false;
            statusStrip.ItemRemoved += delegate(object sender, ToolStripItemEventArgs e) {
                eventInvoked = true;
            };
            statusStrip.Items.RemoveAt(0);
            Assert.IsTrue(eventInvoked,
                          "Event should be invoked when items removed.");
        }
Beispiel #20
0
        private Atk.Attribute [] GetAttributesInRange(int start, int end)
        {
            CG.List <Atk.Attribute> attrs = new CG.List <Atk.Attribute> ();

            IRawElementProviderSimple prov = resource.Provider;

            if (prov == null)
            {
                return(attrs.ToArray());
            }

            ITextProvider textProvider
                = prov.GetPatternProvider(TextPatternIdentifiers.Pattern.Id)
                  as ITextProvider;

            if (textProvider == null)
            {
                return(attrs.ToArray());
            }

            ITextRangeProvider textRange = GetTextRange(start, end);

            foreach (Atk.TextAttribute attr in SUPPORTED_ATTRS)
            {
                AddTextAttribute(attrs, attr, textRange);
            }

            return(attrs.ToArray());
        }
        public ExpandCollapseButton(IRawElementProviderSimple provider) : base(provider)
        {
            ec_prov = (IExpandCollapseProvider)provider.GetPatternProvider(
                ExpandCollapsePatternIdentifiers.Pattern.Id);

            Role = Atk.Role.ToggleButton;
        }
Beispiel #22
0
        internal static void IDockProviderDockPositionTest(IRawElementProviderSimple provider, Control control)
        {
            IDockProvider dockProvider = (IDockProvider)provider.GetPatternProvider(DockPatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(dockProvider, "Dock provider should not be null");

            DockStyle dockOrig = control.Dock;

            control.Dock = DockStyle.Top;
            Assert.AreEqual(DockPosition.Top, dockProvider.DockPosition, "DockPosition Top");
            control.Dock = DockStyle.Bottom;
            Assert.AreEqual(DockPosition.Bottom, dockProvider.DockPosition, "DockPosition Bottom");
            control.Dock = DockStyle.Left;
            Assert.AreEqual(DockPosition.Left, dockProvider.DockPosition, "DockPosition Left");
            control.Dock = DockStyle.Right;
            Assert.AreEqual(DockPosition.Right, dockProvider.DockPosition, "DockPosition Right");
            if (!(control is Splitter))
            {
                control.Dock = DockStyle.Fill;
                Assert.AreEqual(DockPosition.Fill, dockProvider.DockPosition, "DockPosition Fill");
                control.Dock = DockStyle.None;
                Assert.AreEqual(DockPosition.None, dockProvider.DockPosition, "DockPosition None");
            }

            control.Dock = dockOrig;
        }
        public void ISelectionItemProviderTest()
        {
            IRawElementProviderSimple childProvider
                = ProviderFactory.GetProvider(tabPage1);

            ISelectionItemProvider sel_item_prov
                = (ISelectionItemProvider)childProvider.GetPatternProvider(
                      SelectionItemPatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(sel_item_prov, "Not returning SelectionItemPatternIdentifiers");

            // Test IsSelected property
            tabControl.SelectTab(0);
            Assert.IsTrue(sel_item_prov.IsSelected, "IsSelected should return true when tab is selected");

            tabControl.SelectTab(1);
            Assert.IsFalse(sel_item_prov.IsSelected, "IsSelected should return false when tab is not selected");

            // Test .Select method and eventing
            bridge.ResetEventLists();

            sel_item_prov.Select();
            Assert.IsTrue(sel_item_prov.IsSelected,
                          "IsSelected should return true when tab is selected through ISelectionItem interface");

            Assert.AreEqual(1, bridge.AutomationPropertyChangedEvents.Count,
                            "No events fired for selection changed");

            Assert.AreEqual(1, bridge.GetAutomationEventCount(SelectionItemPatternIdentifiers.ElementSelectedEvent),
                            "IsSelected property change not fired");
        }
Beispiel #24
0
        public ComboBox(IRawElementProviderSimple provider) : base(provider)
        {
            if (!(provider is IRawElementProviderFragment))
            {
                throw new ArgumentException("Provider should be IRawElementProviderFragment");
            }

            this.Role = Atk.Role.ComboBox;

            selProvider = (ISelectionProvider)provider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id);

            if (selProvider == null)
            {
                throw new ArgumentException("ComboBoxProvider should always implement ISelectionProvider");
            }

            selectionHelper =
                new SelectionProviderUserHelper((IRawElementProviderFragment)Provider,
                                                selProvider, true);

            var providersSelected = selProvider.GetSelection();

            if (providersSelected != null && providersSelected.Length == 1)
            {
                Name = (string)providersSelected [0].GetPropertyValue(AEIds.NameProperty.Id);
            }
        }
        public void IRangeValueProviderSetValueTest()
        {
            ProgressBar progressBar            = CreateProgressBar();
            IRawElementProviderSimple provider =
                ProviderFactory.GetProvider(progressBar);

            IRangeValueProvider rangeValueProvider = (IRangeValueProvider)
                                                     provider.GetPatternProvider(RangeValuePatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(rangeValueProvider,
                             "Not returning RangeValuePatternIdentifiers.");

            try {
                double minValue = progressBar.Minimum - 1;
                rangeValueProvider.SetValue(minValue);
                Assert.Fail("ArgumentOutOfRangeException not thrown.");
            } catch (ArgumentOutOfRangeException) { }

            try {
                double maxValue = progressBar.Maximum + 1;
                rangeValueProvider.SetValue(maxValue);
                Assert.Fail("ArgumentOutOfRangeException not thrown.");
            } catch (ArgumentOutOfRangeException) { }

            double value = 50;

            rangeValueProvider.SetValue(value);
            Assert.AreEqual(value, progressBar.Value, "SetValue value");
        }
Beispiel #26
0
        public void InvokeTest()
        {
            Button button = new Button();
            IRawElementProviderSimple provider       = ProviderFactory.GetProvider(button);
            IInvokeProvider           invokeProvider = (IInvokeProvider)
                                                       provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);

            bool buttonClicked = false;

            button.Click += delegate(object sender, EventArgs e) {
                buttonClicked = true;
            };

            invokeProvider.Invoke();
            Assert.IsTrue(buttonClicked,
                          "Click should fire when button is enabled");

            buttonClicked  = false;
            button.Enabled = false;
            try {
                invokeProvider.Invoke();
                Assert.Fail("Expected ElementNotEnabledException");
            } catch (ElementNotEnabledException) {
                // Awesome, this is expected
            } catch (Exception e) {
                Assert.Fail("Expected ElementNotEnabledException, " +
                            "but got exception with message: " +
                            e.Message);
            }
            Assert.IsFalse(buttonClicked,
                           "Click should not fire when button is disabled");
        }
        public void ITransformProviderVerticalMoveTest()
        {
            Splitter splitter = new Splitter();
            IRawElementProviderSimple provider =
                ProviderFactory.GetProvider(splitter);

            ITransformProvider transformProvider = (ITransformProvider)
                                                   provider.GetPatternProvider(TransformPatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(transformProvider,
                             "Not returning TransformPatternIdentifiers.");

            Assert.AreEqual(-1, splitter.SplitPosition,
                            "Splitter doesn't dock to any control");

            double x = 50, y = 50;

            Panel panel = new Panel();

            panel.Dock    = DockStyle.Left;
            splitter.Dock = DockStyle.Left;
            Form.Controls.Add(splitter);
            Form.Controls.Add(panel);
            transformProvider.Move(x, y);
            Assert.AreEqual((int)x, splitter.SplitPosition, "Left position");

            panel.Dock    = DockStyle.Right;
            splitter.Dock = DockStyle.Right;
            transformProvider.Move(x, y);
            Assert.AreEqual((int)x, splitter.SplitPosition, "Right position");
        }
Beispiel #28
0
        object?IRawElementProviderSimple.GetPatternProvider(UIA patternId)
        {
            object?obj = publicIRawElementProviderSimple.GetPatternProvider(patternId);

            if (obj is null)
            {
                return(null);
            }

            // we always want to return the internal accessible object
            return(patternId switch
            {
                UIA.ExpandCollapsePatternId => (IExpandCollapseProvider)this,
                UIA.ValuePatternId => (IValueProvider)this,
                UIA.RangeValuePatternId => (IRangeValueProvider)this,
                UIA.TogglePatternId => (IToggleProvider)this,
                UIA.TablePatternId => (ITableProvider)this,
                UIA.TableItemPatternId => (ITableItemProvider)this,
                UIA.GridPatternId => (IGridProvider)this,
                UIA.GridItemPatternId => (IGridItemProvider)this,
                UIA.InvokePatternId => (IInvokeProvider)this,
                UIA.LegacyIAccessiblePatternId => (ILegacyIAccessibleProvider)this,
                UIA.SelectionPatternId => (ISelectionProvider)this,
                UIA.SelectionItemPatternId => (ISelectionItemProvider)this,
                UIA.ScrollItemPatternId => (IScrollItemProvider)this,
                UIA.MultipleViewPatternId => (IMultipleViewProvider)this,
                UIA.TextPatternId => (ITextProvider)this,
                UIA.TextPattern2Id => (ITextProvider2)this,
                _ => null
            });
Beispiel #29
0
        public void ISelectionProviderEventTest()
        {
            TabControl tc  = new TabControl();
            TabPage    tp1 = new TabPage();
            TabPage    tp2 = new TabPage();

            tc.Controls.Add(tp1);
            tc.Controls.Add(tp2);
            Form.Controls.Add(tc);

            IRawElementProviderSimple provider
                = ProviderFactory.GetProvider(tc);

            ISelectionProvider selectionProvider
                = provider.GetPatternProvider(
                      SelectionPatternIdentifiers.Pattern.Id) as ISelectionProvider;

            Assert.IsNotNull(selectionProvider, "Not returning SelectionPatternIdentifiers.");

            tc.SelectTab(0);

            // Case 1: Select currently selected tab
            bridge.ResetEventLists();
            tc.SelectTab(0);
            Assert.AreEqual(0, bridge.AutomationEvents.Count,
                            "EventCount after selecting selected tab");

            // Case 2: Select different tab
            bridge.ResetEventLists();
            tc.SelectTab(1);
            Assert.AreEqual(1,
                            bridge.GetAutomationPropertyEventCount(SelectionPatternIdentifiers.SelectionProperty),
                            "EventCount after selecting new tab");

            IRawElementProviderSimple[] pageProviders
                = selectionProvider.GetSelection();
            Assert.IsNotNull(pageProviders, "Null selection returned");
            Assert.AreEqual(1, pageProviders.Length,
                            "Less/More than one selected page returned");

            IRawElementProviderSimple child
                = ((IRawElementProviderFragmentRoot)provider)
                  .Navigate(NavigateDirection.FirstChild);

            Assert.IsNotNull(child, "First child is null");

            child = ((IRawElementProviderFragment)child)
                    .Navigate(NavigateDirection.NextSibling);
            Assert.IsNotNull(child, "Second child is null");

            Assert.AreEqual(child, pageProviders[0],
                            "Selected child and second child aren't equal");

            IRawElementProviderSimple pageProvider = pageProviders[0];

            // TODO: flesh this out when we implement TabPageProvider
            Assert.IsNotNull(pageProvider);
        }
Beispiel #30
0
        public Hyperlink(IRawElementProviderSimple provider) : base(provider)
        {
            invokeProvider = (IInvokeProvider)provider.GetPatternProvider(InvokePatternIdentifiers.Pattern.Id);
            hypertext      = (IHypertext)invokeProvider;
            links          = new List <HyperlinkObject> ();
            Role           = Atk.Role.Label;

            textExpert = TextImplementorFactory.GetImplementor(this, provider);
        }