GetCurrentPattern() public method

public GetCurrentPattern ( AutomationPattern pattern ) : object
pattern AutomationPattern
return object
Example #1
0
 public void executePattern(AutomationElement subject, AutomationPattern inPattern)
 {
     switch (inPattern.ProgrammaticName)
     {
         case "InvokePatternIdentifiers.Pattern":
             {
                 InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern);
                 invoke.Invoke();
                 break;
             }
         case "SelectionItemPatternIdentifiers.Pattern":
             {
                 SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern);
                 select.Select();
                 break;
             }
         case "TogglePatternIdentifiers.Pattern":
             {
                 TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern);
                 toggle.Toggle();
                 break;
             }
         case "ExpandCollapsePatternIdentifiers.Pattern":
             {
                 ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                 // exColPat.Expand();
                 break;
             }
     }
 }
Example #2
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal ScrollItemPatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
            :
            base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
        {
            Comment("Creating ScrollItemTests");

            _pattern = (ScrollItemPattern)GetPattern(m_le, m_useCurrent, ScrollItemPattern.Pattern);
            if (_pattern == null)
                ThrowMe(CheckType.IncorrectElementConfiguration, Helpers.PatternNotSupported + ": ScrollItemPattern");

            // Find the ScrollPattern
            _container = m_le;

            while (_container != null && !(bool)_container.GetCurrentPropertyValue(AutomationElement.IsScrollPatternAvailableProperty))
                _container = TreeWalker.ControlViewWalker.GetParent(_container);

            // Check to see if we actual found the container of the scrollitem
            if (_container == null)
                ThrowMe(CheckType.IncorrectElementConfiguration, "Element does not have a container with ScrollPattern");

            Comment("Found scroll container: " + Library.GetUISpyLook(_container));

            _scrollPattern = (ScrollPattern)_container.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;

        }
		/// -------------------------------------------------------------------
		/// <summary></summary>
		/// -------------------------------------------------------------------
		public MultipleViewTests(AutomationElement element, TestPriorities priority, string dirResults, bool testEvents, TypeOfControl typeOfControl, IApplicationCommands commands)
            :
            base(element, TestSuite, priority, typeOfControl, TypeOfPattern.MultipleView, dirResults, testEvents, commands)
        {
            m_pattern = (MultipleViewPattern)element.GetCurrentPattern(MultipleViewPattern.Pattern);
            if (m_pattern == null)
                throw new Exception(Helpers.PatternNotSupported);
        }
Example #4
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        protected TogglePatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
            :
            base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
        {
            _pattern = (TogglePattern)element.GetCurrentPattern(TogglePattern.Pattern);

            if (_pattern == null)
                throw new Exception("TogglePattern: " + Helpers.PatternNotSupported);
        }
Example #5
0
        public static void Check(AutomationElement element)
        {
            // element.SetFocus();
            //SendKeys.SendWait(" ");

            TogglePattern togglePattern = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

               togglePattern.Toggle();
        }
Example #6
0
        /// <summary>
        /// Gets the content of the AutomationElement of control type DataGrid.
        /// </summary>
        /// <param name="dataGrid">A data grid control.</param>
        /// <returns>A data table containing the contents of the passed data grid.</returns>
        public static DataTable GetDataGridContent(AutomationElement dataGrid, string tableName = "DataGrid")
        {
            if (dataGrid.Current.ControlType != ControlType.DataGrid)
            {
                throw new Exception("Invalid control type passed to GetDataGridContent.");
            }

            try
            {
                GridPattern gp = (GridPattern)dataGrid.GetCurrentPattern(GridPattern.Pattern);
                TablePattern tp = (TablePattern)dataGrid.GetCurrentPattern(TablePattern.Pattern);
                AutomationElement[] headers = tp.Current.GetColumnHeaders();
                DataTable dt = new DataTable(tableName);

                foreach (AutomationElement columnHeader in headers)
                {
                    dt.Columns.Add(columnHeader.Current.Name, typeof(String));
                }

                int colCount = gp.Current.ColumnCount;
                int rowCount = gp.Current.RowCount;

                for (int r = 0; r < rowCount; r++)
                {
                    DataRow dr = dt.NewRow();

                    for (int c = 0; c < colCount; c++)
                    {
                        dr[c] = gp.GetItem(r, c).Current.Name;
                    }
                    dt.Rows.Add(dr);
                }
                return dt;
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return new DataTable();
            }
        }
Example #7
0
        public static string GetText(AutomationElement element)
        {
            string content = string.Empty;

            TextPattern txtPattern = element.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

            if (txtPattern != null)
            {
                content = txtPattern.DocumentRange.GetText(-1);
            }

            return content;
        }
Example #8
0
 private void EmptyTextFromChild(AutomationElement element)
 {
     if (element.GetSupportedPatterns().Contains(ValuePattern.Pattern))
     {
         ((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern)).SetValue(string.Empty);
     }
     else if (element.GetSupportedPatterns().Contains(TextPattern.Pattern))
     {
         TextPatternRange document =
             ((TextPattern)Element.GetCurrentPattern(TextPattern.Pattern)).DocumentRange;
         AutomationElement[] children = document.GetChildren();
         foreach (var child in children)
         {
             EmptyTextFromChild(child);
         }
     }
 }
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal SelectionItemPatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
            :
            base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
        {
            _pattern = (SelectionItemPattern)GetPattern(m_le, m_useCurrent, SelectionItemPattern.Pattern);
            if (_pattern == null)
                throw new Exception(Helpers.PatternNotSupported + ": SelectionItemPattern");

            _selectionContainer = _pattern.Current.SelectionContainer;

            if (_selectionContainer != null)
            {
                _selectionPattern = _selectionContainer.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
                if (_selectionPattern == null)
                    throw new ArgumentException("Could not find the SelectionContainer's SelectionPattern");
            }

        }
Example #10
0
        public AppHost(string program, string args)
        {
            // Start up the program and find it
            _process = Process.Start(program, args);
            _hwnd = ActiveWaitForHwnd(_process.Id);
            if (_hwnd == IntPtr.Zero)
            {
                throw new InvalidOperationException("app never stabilized");
            }

            // Find it
            _element = AutomationElement.FromHandle(_hwnd);
            if (_element == null)
            {
                throw new InvalidOperationException();
            }

            _windowPattern = (WindowPattern)_element.GetCurrentPattern(WindowPattern.Pattern);
        }
Example #11
0
        public ExplorerHost()
        {
            // Start up Explorer and find it
            System.Diagnostics.Process.Start("cmd.exe", "/c start %SystemDrive%\\windows\\system32");

            // Wait briefly
            System.Threading.Thread.Sleep(2000 /* ms */);

            // Find it
            _element = AutomationElement.RootElement.FindFirst(TreeScope.Children,
                new PropertyCondition(AutomationElement.NameProperty, "system32"));
            if (_element == null)
            {
                throw new InvalidOperationException();
            }

            _hwnd = _element.Current.NativeWindowHandle;

            _windowPattern = (WindowPattern)_element.GetCurrentPattern(WindowPattern.Pattern);
        }
Example #12
0
        private static WindowPattern GetWindowPattern(AutomationElement targetControl)
        {
            WindowPattern windowPattern = null;

            try
            {
                windowPattern = targetControl.GetCurrentPattern(WindowPattern.Pattern)
                    as WindowPattern;
            }
            catch (InvalidOperationException)
            {
                // object doesn't support the WindowPattern control pattern 
                return null;
            }
            // Make sure the element is usable. 
            if (false == windowPattern.WaitForInputIdle(10000))
            {
                // Object not responding in a timely manner 
                return null;
            }
            return windowPattern;
        }
Example #13
0
        /// <summary>
        /// Gets the first selected content of the AutomationElement of control type ComboBox.
        /// </summary>
        /// <param name="comboBoxControl">A combobox control.</param>
        /// <returns>Only the first selected item in text format.</returns>
        public static string GetComboBoxContent(AutomationElement comboBoxControl)
        {
            if (comboBoxControl.Current.ControlType != ControlType.ComboBox)
            {
                throw new Exception("Invalid control type passed to GetRadioButtonCheckState.");
            }

            try
            {
                SelectionPattern sp = (SelectionPattern)comboBoxControl.GetCurrentPattern(SelectionPattern.Pattern);
                AutomationElement[] selected = sp.Current.GetSelection();
                if (selected.Length > 0)
                {
                    return selected[0].Current.Name;
                }
                return String.Empty;
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return String.Empty;
            }
        }
Example #14
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TS_CurrentEqualsSelection(AutomationElement container, ArrayList array, CheckType checkType)
        {
            int count = 0;

            SelectionPattern sp = container.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
            if (sp == null)
                ThrowMe(checkType, "Element does not support SelectionPattern");

            AutomationElement[] les = sp.Current.GetSelection();
            Comment("There are " + les.Length + " selected items according to element.Current.GetSelection()");

            Comment("There should be " + array.Count + " items selected");
            if (!les.Length.Equals(array.Count))
                ThrowMe(checkType, "m_pattern.Selection == " + count + ", but there should be " + array.Count + " items selected");


            Comment("Now compare that Current.GetSelection() is what should be selected");
            foreach (AutomationElement le in les)
            {
                Comment(" - Verify: (" + Library.GetUISpyLook(le) + ").IsSelected = true");
                if (array.IndexOf(le).Equals(false))
                    ThrowMe(checkType, "The selected elements does not equal to what it should be");
            }

            // Now compare what array says
            SelectionItemPattern sip;

            Comment("Now compare what we expected to be selected (items we called Select() on");
            foreach (AutomationElement le in array)
            {
                Comment(" - Verify: (SelectionItemPattern)" + Library.GetUISpyLook(le) + ".GetCurrentPattern(SelectionItemPattern.Pattern).IsSelected should be true");
                sip = (SelectionItemPattern)le.GetCurrentPattern(SelectionItemPattern.Pattern);
                if (sip.Current.IsSelected.Equals(false))
                    ThrowMe(CheckType.Verification, "Element is not selected when it should be");
            }

            m_TestStep++;
        }
Example #15
0
        public Table(AutomationElement element)
            : base(element) {
                _pattern = (GridPattern)element.GetCurrentPattern(GridPattern.Pattern);

        }
Example #16
0
 protected void Select(AutomationElement element)
 {
     SelectionItemPattern select = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern);
     select.Select();
 }
Example #17
0
 protected void Click(AutomationElement element)
 {
     var click = element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
     click.Invoke();
 }
Example #18
0
        /// -------------------------------------------------------------------
        /// <summary>HELPER: Obtains the pattern object and returns true or false depending on success</summary>
        /// -------------------------------------------------------------------
        private static bool GetPatternObject(AutomationElement element, AutomationPattern automationPattern, ref object patternObj)
        {
            bool succeeded = true;
            try
            {
                patternObj = element.GetCurrentPattern(automationPattern);
            }
            catch (InvalidOperationException exception)
            {
                Dump(exception.ToString(), true, element);
                succeeded = false;
            }
            return succeeded;

        }
Example #19
0
 public static void AutomationElementGetCurrentPattern(AutomationElement element)
 {
     Dump("GetCurrentPattern(InvokePattern.Pattern)", true, element);
     try
     {
         object obj = element.GetCurrentPattern(InvokePattern.Pattern);
     }
     catch (Exception exception)
     {
         VerifyException(element, exception, 
             typeof(ElementNotAvailableException),
             typeof(InvalidOperationException) /*{"Unsupported Pattern"} */
             );
     }
 }
Example #20
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        private void TS_CollapseMenu(AutomationElement menu, CheckType checkType)
        {
            if (false == (bool)menu.GetCurrentPropertyValue(AutomationElement.IsExpandCollapsePatternAvailableProperty))
            {
                ThrowMe(checkType, "Menu does not support ExpandCollapsePattern");
            }

            int timeout = 0;

            ExpandCollapsePattern ecp = menu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
            ecp.Collapse();

            // Yikes sleep!  But we are testing events, so cannot rely on eventing to determine when we are done.
            while (ecp.Current.ExpandCollapseState != ExpandCollapseState.Collapsed && timeout < MAX_TIME)
            {
                Thread.Sleep(INCREMENT);
                timeout += INCREMENT;
            }

            m_TestStep++;
        }
Example #21
0
        private void DoOperations()
        {
            InternetExplorerOptions ieOptions = new InternetExplorerOptions();

            ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

            //IWebDriver driverIE = new InternetExplorerDriver(@"D:\COMPARTIDO_PUBLICO\RPA\TCS RPA V1.2 - Training\Sample\Automation - Proceso Cese - JJRDC\Mainframe Automation\Mainframe Automation Solution\packages\Selenium.WebDriver.IEDriver.3.5.1\driver", ieOptions);

            IWebDriver driverIE = new InternetExplorerDriver(System.Configuration.ConfigurationManager.AppSettings["IEDriverPath"], ieOptions);

            //driverIE.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
            driverIE.Navigate().GoToUrl("http://*****:*****@id,'btnAlertaDismiss')]")).Click();
            driverIE.FindElement(By.XPath("//*[contains(@id,'btnAlertaDismiss')]")).Click();

            //acts.SendKeys(Keys.Enter);
            //acts.SendKeys(Keys.Enter);
        }
Example #22
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TS_IsSelected(AutomationElement element, bool ShouldElementBeSelected, CheckType checkType)
        {
            SelectionItemPattern sip = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern);

            // Check to make sure all elements in 
            if (!sip.Current.IsSelected.Equals(ShouldElementBeSelected))
                ThrowMe(checkType, "IsSelected returned " + !ShouldElementBeSelected + " but expected " + ShouldElementBeSelected);

            Comment("IsSelected(" + Library.GetUISpyLook(element) + ") = " + sip.Current.IsSelected.Equals(ShouldElementBeSelected));
            m_TestStep++;
        }
Example #23
0
 /// -------------------------------------------------------------------
 /// <summary></summary>
 /// -------------------------------------------------------------------
 internal void SetPatterns(AutomationElement element)
 {
     if (element == null)
         return;
     foreach (AutomationPattern ap in element.GetSupportedPatterns())
     {
         Comment("Element supports pattern: " + Automation.PatternName(ap).ToString());
         m_cachedPatternList.Add(element.GetCurrentPattern(ap));
     }
 }
Example #24
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TS_AddElementToSelection(AutomationElement element, Type expectedException, CheckType checkType)
        {
            string call = "SelectionItemPattern.AddToSelection()";
            try
            {
                SelectionItemPattern sip = element.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                if (sip == null)
                    ThrowMe(CheckType.Verification, "Could not get SelectionItemPattern for " + Library.GetUISpyLook(element));

                Comment("Before calling " + call + " on LE(" + Library.GetUISpyLook(element) + ").IsSelected = " + sip.Current.IsSelected);

                sip.AddToSelection();

                Thread.Sleep(1);
                Comment("After calling " + call + " on LE(" + Library.GetUISpyLook(element) + ").IsSelected = " + sip.Current.IsSelected);
            }
            catch (Exception actualException)
            {
				if (Library.IsCriticalException(actualException))
                    throw;

                Comment("Exception occured : " + actualException.GetType().ToString());
                TestException(expectedException, actualException, call, checkType);
                m_TestStep++;
                return;
            }
            TestNoException(expectedException, call, checkType);

            m_TestStep++;
        }
Example #25
0
        /// -------------------------------------------------------------------
        /// <summary>Helper: Press button</summary>
        /// -------------------------------------------------------------------
        void HelperPressButton(AutomationElement element, ActionMethod actionBY, CheckType checkType)
        {
            Library.ValidateArgumentNonNull(element, "Button AutomationElement");

            string name = element.Current.Name;

            switch (actionBY)
            {
                case ActionMethod.KeyPadOnly:
                    {
                        string buffer = element.Current.AccessKey;
                        if (!string.IsNullOrEmpty(buffer))
                        {
                            // There is an access key so use it
                            Comment("Pressing keyboard access key \"" + element.Current.AccessKey + "\"");
                            Input.SendKeyboardInput(element.Current.AccessKey);
                        }
                        else
                        {
                            // No access key so set focus and press enter
                            Comment("Setting focus to \"{0}\" and pressing ENTER", element.Current.Name);
                            element.SetFocus();
                            Input.SendKeyboardInput(System.Windows.Input.Key.Enter);
                        }
                    }
                    break;
                case ActionMethod.MouseClick:
                    {
                        Comment("Moving mouse to \"" + element.Current.Name + "\" and left clicking");
                        Input.MoveToAndClick(element);
                    }
                    break;
                default:
                    {
                        if (!(bool)element.GetCurrentPropertyValue(AutomationElement.IsInvokePatternAvailableProperty))
                            ThrowMe(checkType, "Button \"" + name + "\" does not support Invoke pattern");

                        Comment("Calling InvokePattern.Invoke() on \"" + name + "\"");
                        ((InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern)).Invoke();
                    }
                    break;
            }
        }
Example #26
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TS_RemoveElementFromSelection(AutomationElement element, Type expectedException, CheckType checkType)
        {

            string call = "SelectionItemPattern.RemoveFromSelection()";
            try
            {
                Comment("Trying to RemoveElementFromSelection(" + Library.GetUISpyLook(element) + ")");
                SelectionItemPattern sip = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern);
                sip.RemoveFromSelection();
                Thread.Sleep(1);
                Comment("After calling RemoveElementFromSelection on LE(" + Library.GetUISpyLook(element) + ").IsSelected = " + sip.Current.IsSelected);
            }
            catch (Exception actualException)
            {
				if (Library.IsCriticalException(actualException))
                    throw;

                Comment("Exception occured : " + actualException.GetType().ToString());
                TestException(expectedException, actualException, call, checkType);
                return;
            }
            TestNoException(expectedException, call, checkType);
            m_TestStep++;
        }
Example #27
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal SelectionItemPattern getSelectionItemPattern(AutomationElement element, CheckType checkType)
        {
            SelectionItemPattern sip = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern);

            if (sip == null)
                ThrowMe(checkType, "\"" + Library.GetUISpyLook(element) + " does not support SelectionItemPattern");

            return sip;
        }
Example #28
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TSC_SelectElement(AutomationElement le, string name, Type expectedException, CheckType checkType)
        {
            SelectionItemPattern sip = le.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;

            if (sip == null)
                ThrowMe(checkType, "Could not get the selection item pattern for " + Library.GetUISpyLook(le));
            else
                Comment("Call Select() on : " + Library.GetUISpyLook(le)); 
            sip.Select();

            m_TestStep++;
        }
Example #29
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        private void TS_InvokePatternInvoke(AutomationElement element, CheckType checkType)
        {
            InvokePattern ip = element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
            if (ip == null)
                ThrowMe(checkType, "Element[" + element.Current.Name + "] does not support InvokePattern");

            ip.Invoke();

            Comment("InvokePattern.Invoke(element[" + element.Current.Name + "])");

            m_TestStep++;
        }
Example #30
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void TS_IsSelectable(AutomationElement element, bool Selectable, CheckType checkType)
        {
            SelectionItemPattern sip = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern);

            if (!((sip != null) == Selectable))
                ThrowMe(checkType, "Element(" + Library.GetUISpyLook(element) + ") does not support the SelectionItemPattern so cannot be selected");

            string does = "does " + (Selectable.Equals(true) ? "" : "not ");

            Comment("Element(" + Library.GetUISpyLook(element) + ") " + does + "supports the SelectionItemPattern");
            m_TestStep++;
        }
Example #31
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        private void TS_ExpandCollapsePatternExpand(AutomationElement element, CheckType checkType)
        {
            ExpandCollapsePattern ecp = element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
            if (ecp == null)
                ThrowMe(checkType, "Element[" + element.Current.Name + "] does not support ExpandCollapsePattern");

            ecp.Expand();
            Comment("Expanded element[" + element.Current.Name);

            m_TestStep++;
        }