public void LabeledByTest()
        {
            MockProvider mockWindow = new MockProvider();

            mockWindow.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                        ControlType.Window.Id);
            mockWindow.SetPropertyValue(AEIds.NativeWindowHandleProperty.Id,
                                        new IntPtr(1234));

            string       labelText = "label text";
            MockProvider mockLabel = new MockProvider();

            mockLabel.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                       ControlType.Text.Id);
            mockLabel.SetPropertyValue(AEIds.NameProperty.Id,
                                       labelText);

            //string buttonText = "click me";
            MockProvider mockButton = new MockProvider();

            mockButton.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                        ControlType.Button.Id);

            AddProvider(mockWindow);
            AddProvider(mockLabel);
            AddProvider(mockButton);

            string windowPath = "/org/mono/UIAutomation/Element/1";
            string labelPath  = "/org/mono/UIAutomation/Element/2";
            string buttonPath = "/org/mono/UIAutomation/Element/3";

            string ourBus = TestHelper.CurrentBus;

            IAutomationElement windowElement = TestHelper.GetElement(ourBus, windowPath);
            IAutomationElement labelElement  = TestHelper.GetElement(ourBus, labelPath);
            IAutomationElement buttonElement = TestHelper.GetElement(ourBus, buttonPath);

            // Verify that we matched up our elements correctly
            Assert.AreEqual(ControlType.Window.Id,
                            windowElement.ControlTypeId,
                            "Window ControlType");
            Assert.AreEqual(ControlType.Text.Id,
                            labelElement.ControlTypeId,
                            "Label ControlType");
            Assert.AreEqual(ControlType.Button.Id,
                            buttonElement.ControlTypeId,
                            "Button ControlType");

            // Test LabeledBy Initial Value
            Assert.AreEqual(string.Empty,
                            buttonElement.LabeledByElementPath,
                            "Default LabeledBy value");

            // Test with LabeledBy Property Set
            mockButton.SetPropertyValue(AEIds.LabeledByProperty.Id,
                                        mockLabel);
            Assert.AreEqual(labelPath,
                            buttonElement.LabeledByElementPath,
                            "Button should be LabeledBy label element now");
        }
        public void CopyTo_GivenElementArray_CopiesElementProxiesToArray()
        {
            var array = new IAutomationElement[elements.Count];

            sut.CopyTo(array, 0);
            CompareCollections(array, elements);
        }
Example #3
0
        public static IAutomationElement GetElement(string ourBus, string path)
        {
            IAutomationElement element =
                Bus.Session.GetObject <IAutomationElement> (ourBus,
                                                            new ObjectPath(path));

            return(element);
        }
        private IAutomationElement SetupBasicWindowElement(MockProvider mockWindow)
        {
            mockWindow.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                        ControlType.Window.Id);
            mockWindow.SetPropertyValue(AEIds.NativeWindowHandleProperty.Id,
                                        new IntPtr(1234));

            AddProvider(mockWindow);

            string ourBus = TestHelper.CurrentBus;

            string windowPath = "/org/mono/UIAutomation/Element/1";

            IAutomationElement windowElement = TestHelper.GetElement(ourBus, windowPath);

            return(windowElement);
        }
        public void BoundingRectangleTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(new DC.Rect(SW.Rect.Empty),
                            windowElement.BoundingRectangle,
                            "Initial value");

            // Test set value
            SW.Rect testVal = new SW.Rect(5, 6, 7, 8);
            mockWindow.SetPropertyValue(AEIds.BoundingRectangleProperty.Id,
                                        testVal);
            Assert.AreEqual(new DC.Rect(testVal),
                            windowElement.BoundingRectangle,
                            "Set value");
        }
        public void ClickablePointTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(new DC.Point(new SW.Point(double.NegativeInfinity,
                                                      double.NegativeInfinity)),
                            windowElement.ClickablePoint,
                            "Initial value");

            // Test set value
            SW.Point testVal = new SW.Point(7, 8);
            mockWindow.SetPropertyValue(AEIds.ClickablePointProperty.Id,
                                        testVal);
            Assert.AreEqual(new DC.Point(testVal),
                            windowElement.ClickablePoint,
                            "Set value");
        }
        public void ItemTypeTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(string.Empty,
                            windowElement.ItemType,
                            "Initial value");

            // Test set value
            object testVal = "extra special window type";

            mockWindow.SetPropertyValue(AEIds.ItemTypeProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.ItemType,
                            "Set value");
        }
        public void IsRequiredForFormTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(false,
                            windowElement.IsRequiredForForm,
                            "Initial value");

            // Test set value
            object testVal = true;

            mockWindow.SetPropertyValue(AEIds.IsRequiredForFormProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.IsRequiredForForm,
                            "Set value");
        }
        public void ProcessIdTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(-1,
                            windowElement.ProcessId,
                            "Initial value");

            // Test set value
            object testVal = 64523;

            mockWindow.SetPropertyValue(AEIds.ProcessIdProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.ProcessId,
                            "Set value");
        }
        public void AcceleratorKeyTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(string.Empty,
                            windowElement.AcceleratorKey,
                            "Initial value");

            // Test set value
            object testVal = "alt+s";

            mockWindow.SetPropertyValue(AEIds.AcceleratorKeyProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.AcceleratorKey,
                            "Set value");
        }
        public void RuntimeIdTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(0,
                            windowElement.RuntimeId.Length,
                            "Initial value");

            // Test set value
            object testVal = new int [] { 5, 6 };

            mockWindow.SetPropertyValue(AEIds.RuntimeIdProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.RuntimeId,
                            "Set value");
        }
        public void LocalizedControlTypeTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(string.Empty,
                            windowElement.LocalizedControlType,
                            "Initial value");

            // Test set value
            object testVal = ControlType.Window.LocalizedControlType;

            mockWindow.SetPropertyValue(AEIds.LocalizedControlTypeProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.LocalizedControlType,
                            "Set value");
        }
        public void OrientationTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(OrientationType.None,
                            windowElement.Orientation,
                            "Initial value");

            // Test set value
            object testVal = OrientationType.Horizontal;

            mockWindow.SetPropertyValue(AEIds.OrientationProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.Orientation,
                            "Set value");
        }
        public void NameTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(string.Empty,
                            windowElement.Name,
                            "Initial value");

            // Test set value
            object testVal = "my cool window";

            mockWindow.SetPropertyValue(AEIds.NameProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.Name,
                            "Set value");
        }
        public void AutomationIdTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(string.Empty,
                            windowElement.AutomationId,
                            "Initial value");

            // Test set value
            int testVal = 3254;

            mockWindow.SetPropertyValue(AEIds.AutomationIdProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal.ToString(),
                            windowElement.AutomationId,
                            "Set value");
        }
        public void ItemStatusTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(string.Empty,
                            windowElement.ItemStatus,
                            "Initial value");

            // Test set value
            object testVal = "all systems go";

            mockWindow.SetPropertyValue(AEIds.ItemStatusProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.ItemStatus,
                            "Set value");
        }
        public void HelpTextTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            // Test initial value
            Assert.AreEqual(string.Empty,
                            windowElement.HelpText,
                            "Initial value");

            // Test set value
            object testVal = "Sample Help Text";

            mockWindow.SetPropertyValue(AEIds.HelpTextProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.HelpText,
                            "Set value");
        }
        public void NativeWindowHandleTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);
            IntPtr originalPtr = (IntPtr)
                                 mockWindow.GetPropertyValue(AEIds.NativeWindowHandleProperty.Id);

            // Test initial value
            mockWindow.SetPropertyValue(AEIds.NativeWindowHandleProperty.Id,
                                        null);
            Assert.AreEqual(0,
                            windowElement.NativeWindowHandle,
                            "Initial value");

            // Test set value
            mockWindow.SetPropertyValue(AEIds.NativeWindowHandleProperty.Id,
                                        originalPtr);
            Assert.AreEqual(originalPtr.ToInt32(),
                            windowElement.NativeWindowHandle,
                            "Set value");
        }
        public void ControlTypeTest()
        {
            MockProvider       mockWindow    = new MockProvider();
            IAutomationElement windowElement =
                SetupBasicWindowElement(mockWindow);

            mockWindow.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                        null);

            // Test initial value
            Assert.AreEqual(-1,
                            windowElement.ControlTypeId,
                            "Initial value");

            // Test set value
            object testVal = ControlType.Window.Id;

            mockWindow.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                        testVal);
            Assert.AreEqual(testVal,
                            windowElement.ControlTypeId,
                            "Set value");
        }
        public void NavigationTest()
        {
            MockFragmentProvider mockWindow = new MockFragmentProvider();

            mockWindow.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                        ControlType.Window.Id);
            mockWindow.SetPropertyValue(AEIds.NativeWindowHandleProperty.Id,
                                        new IntPtr(1234));

            string labelText = "label text";
            MockFragmentProvider mockLabel = new MockFragmentProvider();

            mockLabel.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                       ControlType.Text.Id);
            mockLabel.SetPropertyValue(AEIds.NameProperty.Id,
                                       labelText);
            mockLabel.SetConnection(mockWindow, NavigateDirection.Parent);
            mockWindow.SetConnection(mockLabel, NavigateDirection.FirstChild);

            MockFragmentProvider mockButton = new MockFragmentProvider();

            mockButton.SetPropertyValue(AEIds.ControlTypeProperty.Id,
                                        ControlType.Button.Id);
            mockButton.SetConnection(mockWindow, NavigateDirection.Parent);
            mockWindow.SetConnection(mockButton, NavigateDirection.LastChild);

            // Sibling stuff
            mockLabel.SetConnection(mockButton, NavigateDirection.NextSibling);
            mockButton.SetConnection(mockLabel, NavigateDirection.PreviousSibling);

            AddProvider(mockWindow);
            AddProvider(mockLabel);
            AddProvider(mockButton);

            string windowPath = "/org/mono/UIAutomation/Element/1";
            string labelPath  = "/org/mono/UIAutomation/Element/2";
            string buttonPath = "/org/mono/UIAutomation/Element/3";

            string ourBus = TestHelper.CurrentBus;

            IAutomationElement windowElement = TestHelper.GetElement(ourBus, windowPath);
            IAutomationElement labelElement  = TestHelper.GetElement(ourBus, labelPath);
            IAutomationElement buttonElement = TestHelper.GetElement(ourBus, buttonPath);

            // Parent
            Assert.AreEqual(string.Empty, windowElement.ParentElementPath, "window has no parent");
            Assert.AreEqual(windowPath, labelElement.ParentElementPath, "label parent is window");
            Assert.AreEqual(windowPath, buttonElement.ParentElementPath, "button parent is window");

            // FirstChild
            Assert.AreEqual(labelPath, windowElement.FirstChildElementPath, "window first child is label");
            Assert.AreEqual(string.Empty, labelElement.FirstChildElementPath, "label has no children");
            Assert.AreEqual(string.Empty, buttonElement.FirstChildElementPath, "button has no children");

            // LastChild
            Assert.AreEqual(buttonPath, windowElement.LastChildElementPath, "window first child is button");
            Assert.AreEqual(string.Empty, labelElement.LastChildElementPath, "label has no children");
            Assert.AreEqual(string.Empty, buttonElement.LastChildElementPath, "button has no children");

            // NextSibling
            Assert.AreEqual(string.Empty, windowElement.NextSiblingElementPath, "window has no siblings");
            Assert.AreEqual(buttonPath, labelElement.NextSiblingElementPath, "label next sibling is button");
            Assert.AreEqual(string.Empty, buttonElement.NextSiblingElementPath, "button has no next sibling");

            // PreviousSibling
            Assert.AreEqual(string.Empty, windowElement.PreviousSiblingElementPath, "window has no siblings");
            Assert.AreEqual(string.Empty, labelElement.PreviousSiblingElementPath, "label has no prev sibling");
            Assert.AreEqual(labelPath, buttonElement.PreviousSiblingElementPath, "button prev sibling is label");
        }
        public void SimpleFormTest()
        {
            Form f = new Form();

            f.Text = "Hello World";
            f.Show();

            string ourBus = TestHelper.CurrentBus;

            IApplication app = TestHelper.GetApplication(ourBus);

            Assert.IsNotNull(app, "Unable to get UiaDbus.IApplication");

            string [] rootElementPaths = app.GetRootElementPaths();
            Assert.AreEqual(1, rootElementPaths.Length);
            Assert.AreEqual("/org/mono/UIAutomation/Element/1", rootElementPaths [0]);

            IAutomationElement element1 = TestHelper.GetElement(ourBus, rootElementPaths [0]);

            Assert.IsNotNull(element1, "Unable to get root element");
            Assert.AreEqual(f.Text,
                            element1.Name,
                            "Root element name");
            Assert.AreEqual(ControlType.Window.Id,
                            element1.ControlTypeId,
                            "Root element control type");

            f.Close();

            rootElementPaths = app.GetRootElementPaths();
            Assert.AreEqual(0, rootElementPaths.Length,
                            "No root elements when window closed");

            bool exceptionOccurred = false;

            try {
                element1.Name.ToString();
            } catch (Exception e) {
                exceptionOccurred = true;
                string expectedMessage = "org.freedesktop.DBus.Error.UnknownMethod: Method \"GetName\" with signature \"\" on interface \"org.mono.UIAutomation.AutomationElement\" doesn't exist";
                Assert.AreEqual(expectedMessage,
                                e.Message,
                                "Unexpected exception when trying to use invalid dbus proxy object");
            }
            Assert.IsTrue(exceptionOccurred,
                          "Expected an exception when trying to use invalid dbus proxy object");

            f = new Form();
            f.Show();

            app = TestHelper.GetApplication(ourBus);

            Assert.IsNotNull(app, "Unable to get UiaDbus.IApplication");

            rootElementPaths = app.GetRootElementPaths();
            Assert.AreEqual(1, rootElementPaths.Length);
            Assert.AreEqual("/org/mono/UIAutomation/Element/2", rootElementPaths [0]);

            element1 = TestHelper.GetElement(ourBus, rootElementPaths [0]);
            Assert.IsNotNull(element1, "Unable to get root element");
            Assert.AreEqual(f.Text,
                            element1.Name,
                            "Root element name");
            Assert.AreEqual(ControlType.Window.Id,
                            element1.ControlTypeId,
                            "Root element control type");
        }