Пример #1
0
        public void CompareAutomationElementsTest()
        {
            Process p = BaseTest.StartApplication(@"SampleForm.exe",
                                                  String.Empty);

            try {
                Thread.Sleep(1000);

                SWA.AutomationElement testFormElement = SWA.AutomationElement.RootElement.FindFirst(SWA.TreeScope.Children,
                                                                                                    new SWA.PropertyCondition(AEIds.ProcessIdProperty,
                                                                                                                              p.Id));
                Assert.IsNotNull(testFormElement,
                                 "window");

                SWA.AutomationElement groupBox1Element = testFormElement.FindFirst(SWA.TreeScope.Children,
                                                                                   new SWA.PropertyCondition(AEIds.ControlTypeProperty,
                                                                                                             SWA.ControlType.Group));
                Assert.IsNotNull(groupBox1Element,
                                 "groupBox1");

                Assert.IsTrue(SWA.Automation.Compare(testFormElement, testFormElement),
                              "Identity");

                SWA.AutomationElement testFormElement2 = SWA.AutomationElement.RootElement.FindFirst(SWA.TreeScope.Children,
                                                                                                     new SWA.PropertyCondition(AEIds.ProcessIdProperty,
                                                                                                                               p.Id));

                Assert.IsTrue(SWA.Automation.Compare(testFormElement, testFormElement2),
                              "Comparing different instances representing the same element");

                Assert.IsFalse(SWA.Automation.Compare(testFormElement, groupBox1Element),
                               "Comparing different elements");

                bool argumentNullRaised = false;
                try {
                    SWA.Automation.Compare(testFormElement, null);
                } catch (ArgumentNullException) {
                    argumentNullRaised = true;
                }
                Assert.IsTrue(argumentNullRaised,
                              "Expected ArgumentNullException");
            } finally {
                p.Kill();
            }
        }
Пример #2
0
        public void RemoveAutomationEventHandlerTest()
        {
            int     eventCount = 0;
            Process p          = BaseTest.StartApplication(@"SampleForm.exe", string.Empty);

            potentiallyRunningProcesses.Add(p);
            SWA.AutomationEventHandler handler = (o, e) => eventCount++;
            Thread.Sleep(2000);              // Waiting a little bit for the application to show up

            SWA.AutomationElement testFormElement
                = SWA.AutomationElement.RootElement.FindFirst(SWA.TreeScope.Children,
                                                              new SWA.PropertyCondition(AEIds.ProcessIdProperty, p.Id));
            Assert.IsNotNull(testFormElement, "window");

            SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.AsyncContentLoadedEvent,
                                                        testFormElement,
                                                        handler);

            BaseTest.AssertRaises <ArgumentException> (
                () => SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.AutomationFocusChangedEvent,
                                                                  testFormElement,
                                                                  handler),
                "SWA.AutomationElementIdentifiers.AutomationFocusChangedEvent");

            BaseTest.AssertRaises <ArgumentException> (
                () => SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.AutomationPropertyChangedEvent,
                                                                  testFormElement,
                                                                  handler),
                "SWA.AutomationElementIdentifiers.AutomationPropertyChangedEvent");

            SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.LayoutInvalidatedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.MenuClosedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.MenuOpenedEvent,
                                                        testFormElement,
                                                        handler);

            BaseTest.AssertRaises <ArgumentException> (
                () => SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.StructureChangedEvent,
                                                                  testFormElement,
                                                                  handler),
                "SWA.AutomationElementIdentifiers.StructureChangedEvent");

            SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.ToolTipClosedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.AutomationElementIdentifiers.ToolTipOpenedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.InvokePatternIdentifiers.InvokedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.SelectionItemPatternIdentifiers.ElementAddedToSelectionEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.SelectionItemPatternIdentifiers.ElementRemovedFromSelectionEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.SelectionItemPatternIdentifiers.ElementSelectedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.SelectionPatternIdentifiers.InvalidatedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.TextPatternIdentifiers.TextChangedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.TextPatternIdentifiers.TextSelectionChangedEvent,
                                                        testFormElement,
                                                        handler);
            SWA.Automation.RemoveAutomationEventHandler(SWA.WindowPatternIdentifiers.WindowOpenedEvent,
                                                        testFormElement,
                                                        handler);

            p.Kill();
        }