Ejemplo n.º 1
0
        protected override string DoImpl()
        {
            var registeredKey = this.ExecutedCommand.Parameters["ID"].ToString();

            var element = this.Automator.ElementsRegistry.GetRegisteredElement(registeredKey);

            ComboBox comboBox = element.FlaUIElement.AsComboBox();

            ExpandCollapseState state = comboBox.ExpandCollapseState;

            return(this.JsonResponse(ResponseStatus.Success, state.ToString()));
        }
        public void ExpandCollapseState_PartiallyExpanded()
        {
            // Arrange
            ExpandCollapseState            expectedValue = ExpandCollapseState.PartiallyExpanded;
            ISupportsExpandCollapsePattern element       =
                FakeFactory.GetAutomationElementForMethodsOfObjectModel(
                    new IBasePattern[] { FakeFactory.GetExpandCollapsePattern(new PatternsData()
                {
                    ExpandCollapsePattern_ExpandCollapseState = expectedValue
                }) }) as ISupportsExpandCollapsePattern;

            #region commented
//if (null == element) {
//    Console.WriteLine("null == element");
//} else {
//    Console.WriteLine("null != element");
//    try {
//        Console.WriteLine(element.ExpandCollapseState.ToString());
//    } catch (Exception e) {
//        Console.WriteLine(e.Message);
//        // throw;
//    }
//}
//var pattern = FakeFactory.GetExpandCollapsePattern(new PatternsData() { ExpandCollapsePattern_ExpandCollapseState = expectedValue });
//if (null == pattern) {
//    Console.WriteLine("null == pattern");
//} else {
//    Console.WriteLine("null != pattern");
//    try {
//        Console.WriteLine(pattern.Current.ExpandCollapseState.ToString());
//    } catch (Exception e2) {
//        Console.WriteLine(e2.Message);
//        // throw;
//    }
//}
            #endregion commented

            // Act
            // Assert
            CmdletUnitTest.TestRunspace.RunAndEvaluateAreEqual(
                @"$input | %{ $_.ExpandCollapseState; }",
                // @"$input | %{ $_.GetSourceElement().ExpandCollapseState; }",
                new [] { element },
                // new [] { (element as IUiElement).GetSourceElement() },
                expectedValue.ToString());
        }
Ejemplo n.º 3
0
        /// ---------------------------------------------------------------
        /// <summary>
        /// Will call the approprate ExpandCollapse state to happen
        /// </summary>
        /// ---------------------------------------------------------------
        void expandCollapseMenu(ExpandCollapseState desiredState)
        {
            ExpandCollapsePattern ecp = this.AutomationElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            _desiredState = desiredState;

            if (ecp == null)
            {
                throw new InvalidOperationException("The element does not support ExpandCallapsePattern");
            }

            _ev.Reset();

            Automation.AddAutomationPropertyChangedEventHandler(
                _element,
                TreeScope.Element,
                new AutomationPropertyChangedEventHandler(ExpandCollapseEventHandler),
                new AutomationProperty[] { ExpandCollapsePattern.ExpandCollapseStateProperty });

            // Cause the state to happen
            switch (desiredState)
            {
            case ExpandCollapseState.Collapsed:
                ecp.Collapse();
                break;

            case ExpandCollapseState.Expanded:
                /* changing to new flexible logging */
                //Logger.LogComment("Expanding " + _element.Current.Name);
                UIVerifyLogger.LogComment("Expanding " + _element.Current.Name);


                // There can be times when there is already another menu opened and
                // we throw an expection, which will dismiss it, do it again.
                try
                {
                    ecp.Expand();
                }
                catch (Exception exception)
                {
                    if (Library.IsCriticalException(exception))
                    {
                        throw;
                    }

                    ecp.Expand();
                }
                break;

            case ExpandCollapseState.LeafNode:
                throw new NotImplementedException();

            case ExpandCollapseState.PartiallyExpanded:
                throw new NotImplementedException();

            default:
                throw new Exception("Have not implemented case for " + desiredState);
            }

            _ev.WaitOne(10000, false);

            while (ecp.Current.ExpandCollapseState != desiredState)
            {
                throw new Exception("ExpandCollapsePattern.ExpandCollapseStateProperty != " + desiredState.ToString());
            }
        }
Ejemplo n.º 4
0
        /// ---------------------------------------------------------------
        /// <summary>
        /// Will call the approprate ExpandCollapse state to happen
        /// </summary>
        /// ---------------------------------------------------------------
        void expandCollapseMenu(ExpandCollapseState desiredState)
        {
            ExpandCollapsePattern ecp = this.AutomationElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            _desiredState = desiredState;

            if (ecp == null)
                throw new InvalidOperationException("The element does not support ExpandCallapsePattern");

            _ev.Reset();

            Automation.AddAutomationPropertyChangedEventHandler(
                _element, 
                TreeScope.Element,
                new AutomationPropertyChangedEventHandler(ExpandCollapseEventHandler),
                new AutomationProperty[] { ExpandCollapsePattern.ExpandCollapseStateProperty });

            // Cause the state to happen
            switch (desiredState)
            {
                case ExpandCollapseState.Collapsed:
                    ecp.Collapse();
                    break;

                case ExpandCollapseState.Expanded:
                    /* changing to new flexible logging */
                    //Logger.LogComment("Expanding " + _element.Current.Name);
                    UIVerifyLogger.LogComment("Expanding " + _element.Current.Name);


                    // There can be times when there is already another menu opened and 
                    // we throw an expection, which will dismiss it, do it again.
                    try
                    {
                        ecp.Expand();
                    }
                    catch (Exception exception)
                    {
						if (Library.IsCriticalException(exception))
                            throw;

                        ecp.Expand();
                    }
                    break;

                case ExpandCollapseState.LeafNode:
                    throw new NotImplementedException();

                case ExpandCollapseState.PartiallyExpanded:
                    throw new NotImplementedException();

                default:
                    throw new Exception("Have not implemented case for " + desiredState);

            }

            _ev.WaitOne(10000, false);

            while (ecp.Current.ExpandCollapseState != desiredState)
            {
                throw new Exception("ExpandCollapsePattern.ExpandCollapseStateProperty != " + desiredState.ToString());
            }
        }
        public void ExpandCollapseState_Collapsed()
        {
            // Arrange
            ExpandCollapseState            expectedValue = ExpandCollapseState.Collapsed;
            ISupportsExpandCollapsePattern element       =
                FakeFactory.GetAutomationElementForMethodsOfObjectModel(
                    new IBasePattern[] { FakeFactory.GetExpandCollapsePattern(new PatternsData()
                {
                    ExpandCollapsePattern_ExpandCollapseState = expectedValue
                }) }) as ISupportsExpandCollapsePattern;

            #region commented
//if (null == element) {
//    Console.WriteLine("null == element");
//} else {
//    Console.WriteLine("null != element");
//    try {
//        Console.WriteLine(element.ExpandCollapseState.ToString());
//    } catch (Exception e) {
//        Console.WriteLine(e.Message);
//        // throw;
//    }
//}
//var pattern = FakeFactory.GetExpandCollapsePattern(new PatternsData() { ExpandCollapsePattern_ExpandCollapseState = expectedValue });
//if (null == pattern) {
//    Console.WriteLine("null == pattern");
//} else {
//    Console.WriteLine("null != pattern");
//    try {
//        Console.WriteLine(pattern.Current.ExpandCollapseState.ToString());
//    } catch (Exception e2) {
//        Console.WriteLine(e2.Message);
//        // throw;
//    }
//}
            #endregion commented

            // Act
            // Assert
            var    data   = new object[] { @"$input | %{ $_.ExpandCollapseState; }", new [] { element }, expectedValue.ToString() };
            Thread thread = new Thread(RunTest);
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(data);

//            CmdletUnitTest.TestRunspace.RunAndEvaluateAreEqual(
//                // @"$input | %{ $_.ExpandCollapseState; }",
//                @"[System.EventHandler]$handler = { $input | %{ $_.ExpandCollapseState; } }; $handler.Invoke();",
//                null, //new [] { element },
//                expectedValue.ToString());
        }