public void Check(bool value) { this.PrepareForReplay(); try { SelectionItemPattern itempattern = (SelectionItemPattern)this._condition.AutomationElement.GetCurrentPattern(SelectionItemPattern.Pattern); bool v = false; if (value) { v = true; } else { v = false; } if (itempattern.Current.IsSelected != v) { itempattern.Select(); } } catch { ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation); } }
//private bool SelectDropDownItem(this AutomationElement comboBoxElement, string item) { // bool itemFound = false; // AutomationElement elementList; // CacheRequest cacheRequest = new CacheRequest(); // cacheRequest.Add(AutomationElement.NameProperty); // cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children; // using (cacheRequest.Activate()) { // // Load the list element and cache the specified properties for its descendants. // Condition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List); // elementList = comboBoxElement.FindFirst(TreeScope.Children, cond); // } // //Loop thru and find the actual ListItem // foreach (AutomationElement child in elementList.CachedChildren) // if (child.Cached.Name == item) { // SelectionItemPattern select = (SelectionItemPattern)child.GetCurrentPattern(SelectionItemPattern.Pattern); // select.Select(); // itemFound = true; // break; // } // return itemFound; //} public void ComboSelect_UsingUIAutomation(string MainWindowName, string ComboBox_AutomationID, string SelectItemText) { AutomationElement desktop = AutomationElement.RootElement; AutomationElement MainWindow = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, MainWindowName)); AutomationElement cboBox, cboItem; cboBox = MainWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, ComboBox_AutomationID)); //Click the combo box to expand the items ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)cboBox.GetCurrentPattern(ExpandCollapsePattern.Pattern); expandPattern.Expand(); //Search the item then click the item cboItem = cboBox.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, SelectItemText)); SelectionItemPattern itemSelect = (SelectionItemPattern)cboItem.GetCurrentPattern(SelectionItemPattern.Pattern); try { itemSelect.Select(); } catch (Exception) { //Ignore this error, bcz some window will wait until the some action has been carried, } //InvokePattern click = (InvokePattern)cboItem.GetCurrentPattern(InvokePattern.Pattern); //click.Invoke(); //click = null; //Release the memory MainWindow = null; //childWindow = null; desktop = null; GC.Collect(); }
public static AutomationElement SetComboBox(this AutomationElement parent, string name, string value) { AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name)); if (box == null) { throw new Exception("ComboBox '" + name + "' not found"); } if (!box.Current.IsEnabled) { throw new Exception("ComboBox '" + name + "' is not enabled"); } ExpandCollapsePattern p = (ExpandCollapsePattern)box.GetCurrentPattern(ExpandCollapsePattern.Pattern); p.Expand(); Thread.Sleep(250); AutomationElement item = box.FindFirstWithRetries(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.NameProperty, value), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem))); if (item == null) { throw new Exception("ComboBoxItem '" + value + "' not found in combo box '" + name + "'"); } SelectionItemPattern si = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern); si.Select(); p.Collapse(); return(box); }
public static void SetSelectedComboBoxItem(AutomationElement comboBox, string item) { AutomationPattern automationPatternFromElement = GetSpecifiedPattern(comboBox, "ExpandCollapsePatternIdentifiers.Pattern"); ExpandCollapsePattern expandCollapsePattern = comboBox.GetCurrentPattern(automationPatternFromElement) as ExpandCollapsePattern; expandCollapsePattern.Expand(); expandCollapsePattern.Collapse(); AutomationElement listItem = comboBox.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, item)); automationPatternFromElement = GetSpecifiedPattern(listItem, "SelectionItemPatternIdentifiers.Pattern"); SelectionItemPattern selectionItemPattern = listItem.GetCurrentPattern(automationPatternFromElement) as SelectionItemPattern; selectionItemPattern.Select(); }
public override UIHandlerAction HandleWindow(IntPtr topLevelhWnd, IntPtr hwnd, Process process, string title, UIHandlerNotification notification) { GlobalLog.LogDebug("Display Properties (Appearance tab) window found."); AutomationElement window = AutomationElement.FromHandle(topLevelhWnd); GlobalLog.LogDebug("Finding Color Scheme combo box and selecting '" + resourceString + "'."); Condition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "1114"); AutomationElement colorSchemeCombo = window.FindFirst(TreeScope.Descendants, cond); cond = new PropertyCondition(AutomationElement.NameProperty, resourceString); AutomationElement item = colorSchemeCombo.FindFirst(TreeScope.Descendants, cond); // Tell the correct combobox item to be selected object patternObject; item.TryGetCurrentPattern(SelectionItemPattern.Pattern, out patternObject); SelectionItemPattern selectionItemPattern = patternObject as SelectionItemPattern; selectionItemPattern.Select(); GlobalLog.LogDebug("Finding and clicking the OK Button"); cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "1"); AutomationElement okBtn = window.FindFirst(TreeScope.Descendants, cond); okBtn.TryGetCurrentPattern(InvokePattern.Pattern, out patternObject); InvokePattern invokePattern = patternObject as InvokePattern; invokePattern.Invoke(); GlobalLog.LogDebug("Waiting for appearance to be applied..."); process.WaitForExit(); return(UIHandlerAction.Abort); }
private static 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; } } }
public void Z_AutomationEventTest() { var automationEventsArray = new [] { new { Sender = (object)null, Args = (AutomationEventArgs)null } }; var automationEvents = automationEventsArray.ToList(); automationEvents.Clear(); AutomationEventHandler handler = (o, e) => automationEvents.Add(new { Sender = o, Args = e }); SelectionItemPattern item1 = (SelectionItemPattern)child1Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern); item1.Select(); AutomationEvent eventId = SelectionItemPattern.ElementSelectedEvent; At.AddAutomationEventHandler(eventId, treeView1Element, TreeScope.Descendants, handler); SelectionItemPattern item2 = (SelectionItemPattern)child2Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern); item2.Select(); Thread.Sleep(500); At.RemoveAutomationEventHandler(eventId, treeView1Element, handler); Assert.AreEqual(1, automationEvents.Count, "event count"); Assert.AreEqual(child2Element, automationEvents [0].Sender, "event sender"); Assert.AreEqual(SelectionItemPattern.ElementSelectedEvent, automationEvents [0].Args.EventId, "EventId"); automationEvents.Clear(); item1.Select(); Thread.Sleep(500); Assert.AreEqual(0, automationEvents.Count, "event count"); }
public void Select(int hwnd, String item) { logger.Debug(String.Format(@"Starting Select({0},""{1}"")", hwnd, item)); AutomationElement element = Find(hwnd); if (element == null) { logger.Warn(String.Format("Element with {0} hwnd wasn't found", hwnd)); } logger.Debug(String.Format(@"Find returns {0}", element.GetHashCode())); AutomationElement tabElement = TreeWalker.RawViewWalker.GetFirstChild(element); while (tabElement != null) { if (tabElement.Current.Name.Equals(item)) { SelectionItemPattern changeTab_aeTabPage = tabElement.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; changeTab_aeTabPage.Select(); return; } tabElement = TreeWalker.RawViewWalker.GetNextSibling(tabElement); } }
public static AutomationElement OpenAppributeFromList(AutomationElement ae, string name) { var datagrid = ae.FindByTypeExt(ControlType.DataGrid)[0]; GridPattern gridPattern = datagrid.GetCurrentPattern(GridPattern.Pattern) as GridPattern; int rowCount = gridPattern.Current.RowCount; List <string> names = new List <string>(); foreach (int i in Enumerable.Range(0, rowCount)) { var item = gridPattern.GetItem(i, 1); if (Regex.IsMatch(item.Current.Name, name)) { AutomationElement row = datagrid.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, (i + 1).ToString())); SelectionItemPattern itemPattern = row.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; itemPattern.Select(); } } ae.FindByNameExt("Modify").PressButtonExt(); var handle = WinApi.Window.FindWindowFromCaptationRegex($".*GD&T.*{name}.*"); AutomationElement newDialog = AutomationElement.FromHandle(handle); return(newDialog); }
public static void AssertSLAttemptToolBarSaveAllForMultipleValidOrdersAndOneInvalidOrder() { AutomationElement aeorderView = CommandingPage <TApp> .aeOrderListView; AutomationElement aeSaveAllButton = CommandingPage <TApp> .aeSaveAllToolBarButton; AutomationElement orderview = aeorderView.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, GetDataFromTestDataFile("Orderone"))); AutomationElementCollection orderviews = aeorderView.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)); System.Threading.Thread.Sleep(2000); Assert.IsTrue(orderviews.Count == 3, "Total order Items Count is Not equal to Three"); //Populate Order 1 with Valid Data SLPopulateOrderDetailsWithData(); Core.InputDevices.Mouse.Instance.Location = new System.Drawing.Point((int)Math.Floor(orderviews[0].Current.BoundingRectangle.X), (int)Math.Floor(orderviews[0].Current.BoundingRectangle.Y)); System.Threading.Thread.Sleep(4000); SelectionItemPattern pattern = orderviews[1].GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); //Populate Order 2 with InValid Data SLPopulateOrderDetailsWithInvalidData(); Core.InputDevices.Mouse.Instance.Location = new System.Drawing.Point((int)Math.Floor(orderviews[1].Current.BoundingRectangle.X), (int)Math.Floor(orderviews[1].Current.BoundingRectangle.Y)); System.Threading.Thread.Sleep(2000); pattern = orderviews[2].GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); //Populate Order 3 with Valid Data SLPopulateOrderDetailsWithData(); Assert.IsFalse(aeSaveAllButton.Current.IsEnabled, "Save All Button Enabled for one of an Invalid Order details"); }
// RopSetSpooler public void SendReceiveAllFolder() { // Get account name var desktop = AutomationElement.RootElement; var nameSpace = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder folder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); string userName = folder.Parent.Name; // Get outlook window var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook"); var window_outlook = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10); // Select Send / Receive tab Condition cd_RibbonTabs = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Send / Receive")); AutomationElement item_RibbonTabs = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300); SelectionItemPattern Pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern); Pattern_RibbonTabs.Select(); // Click the "Send/Receive All Folders" button Condition cd_sendReceiveFolders = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Send/Receive All Folders")); AutomationElement item_sendReceiveFolders = Utilities.WaitForElement(window_outlook, cd_sendReceiveFolders, TreeScope.Descendants, 300); InvokePattern Pattern_cateExpandGroup = (InvokePattern)item_sendReceiveFolders.GetCurrentPattern(InvokePattern.Pattern); Pattern_cateExpandGroup.Invoke(); bool result = MessageParser.ParseMessage(); Assert.IsTrue(result, "Case failed, check the details information in error.txt file."); }
public void Select(int hwnd, int index) { int count = 0; logger.Debug(String.Format(@"Starting Select({0},{1})", hwnd, index)); AutomationElement element = Find(hwnd); if (element == null) { logger.Warn(String.Format("Element with {0} hwnd wasn't found", hwnd)); } AutomationElement tabElement = TreeWalker.RawViewWalker.GetFirstChild(element); while (tabElement != null) { if (count == index) { SelectionItemPattern changeTab_aeTabPage = tabElement.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; changeTab_aeTabPage.Select(); return; } else { count++; } tabElement = TreeWalker.RawViewWalker.GetNextSibling(tabElement); } }
public void Select() { SelectionItemPattern select = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern); select.Select(); ScrollIntoView(); }
private static bool SelectComboboxItem(AutomationElement comboBox, string item) { if (comboBox == null) { return(false); } // Get the list box within the combobox AutomationElement listBox = comboBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List)); if (listBox == null) { return(false); } // Search for item within the listbox AutomationElement listItem = listBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, item)); if (listItem == null) { return(false); } // Check if listbox item has SelectionItemPattern object objPattern; if (true == listItem.TryGetCurrentPattern(SelectionItemPatternIdentifiers.Pattern, out objPattern)) { SelectionItemPattern selectionItemPattern = objPattern as SelectionItemPattern; selectionItemPattern.Select(); // Invoke Selection return(true); } return(false); }
public void Select(string item) { this.PrepareForReplay(); int itemindex = -1; AutomationElementCollection alllabitem = this._childs; SelectionItemPattern labitempattern = null; if (item.IndexOf('#') == 0) { itemindex = Convert.ToInt16(item.Substring(1)); if (alllabitem.Count - 1 < itemindex) { ControlSearcher.ThrowError(ErrorType.OutRange); } else { labitempattern = (SelectionItemPattern)alllabitem[itemindex].GetCurrentPattern(SelectionItemPattern.Pattern); labitempattern.Select(); return; } } else { for (int i = 0; i < alllabitem.Count; i++) { if (alllabitem[i].Current.Name.Trim() == item) { labitempattern = (SelectionItemPattern)alllabitem[i].GetCurrentPattern(SelectionItemPattern.Pattern); labitempattern.Select(); return; } } } ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist); }
protected override void Execute() { Condition controlCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, ControlId); var element = MainWindow.FindFirst(TreeScope.Descendants, controlCondition); if (element != null) { ExpandCollapsePattern expandPattern = null; try { expandPattern = (ExpandCollapsePattern)element.GetCurrentPattern(ExpandCollapsePattern.Pattern); expandPattern.Expand(); //expandPattern.Collapse(); } catch (Exception) { } AutomationElementCollection comboboxItems = element.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)); foreach (AutomationElement automationElement in comboboxItems) { string elementValue = automationElement.Current.Name; if (!string.IsNullOrEmpty(elementValue) && elementValue.Trim().ToLower().Equals(this.Value.Trim().ToLower())) { //Finding the pattern which need to select SelectionItemPattern selectPattern = (SelectionItemPattern)automationElement.GetCurrentPattern(SelectionItemPattern.Pattern); selectPattern.Select(); } } } }
private void timerFindSecurityRDC_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { IntPtr rdhWnd = IntPtr.Zero; IntPtr rdShWnd = IntPtr.Zero; IntPtr rdVMhWnd = IntPtr.Zero; //increment counter timerFindSecurityRDCCount++; //stop the timer timerFindSecurityRDC.Stop(); rdShWnd = (IntPtr)FindWindow("#32770", "Windows Security"); //CLicking use another account if (rdShWnd != IntPtr.Zero) { AutomationElement rdSelectAccount = AutomationElement.FromHandle(rdShWnd); PropertyCondition rdSAC1 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem); PropertyCondition rdSAC2 = new PropertyCondition(AutomationElement.NameProperty, "Use another account"); AutomationElement rdSelected = rdSelectAccount.FindFirst(TreeScope.Descendants, new AndCondition(rdSAC1, rdSAC2)); SelectionItemPattern LineItemsSelect = (SelectionItemPattern)rdSelected.GetCurrentPattern(SelectionItemPattern.Pattern); LineItemsSelect.Select(); //entering username AutomationElement rdSecurity1 = AutomationElement.FromHandle(rdShWnd); PropertyCondition rdSC1 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit); PropertyCondition rdSC2 = new PropertyCondition(AutomationElement.NameProperty, "User name"); AutomationElement rdUsername = rdSecurity1.FindFirst(TreeScope.Descendants, new AndCondition(rdSC1, rdSC2)); Win32.SendMessage((IntPtr)rdUsername.Current.NativeWindowHandle, Win32.WM_SETTEXT, 0, ""); Win32.SendMessage((IntPtr)rdUsername.Current.NativeWindowHandle, Win32.WM_SETTEXT, 0, SelectedDomainName + "\\" + SelectedAccountName); //entering password Password = GetPassword(SelectedAccountName); AutomationElement rdSecurity = AutomationElement.FromHandle(rdShWnd); PropertyCondition rdSC3 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit); PropertyCondition rdSC4 = new PropertyCondition(AutomationElement.NameProperty, "Password"); AutomationElement rdPassword = rdSecurity.FindFirst(TreeScope.Descendants, new AndCondition(rdSC3, rdSC4)); Win32.SendMessage((IntPtr)rdPassword.Current.NativeWindowHandle, Win32.WM_SETTEXT, 0, ""); Win32.SendMessage((IntPtr)rdPassword.Current.NativeWindowHandle, Win32.WM_SETTEXT, 0, Password); //clicking ok after passing credentials AutomationElement rdOk = AutomationElement.FromHandle(rdShWnd); PropertyCondition rdOC3 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button); PropertyCondition rdOC4 = new PropertyCondition(AutomationElement.NameProperty, "OK"); AutomationElement rdClickOk = rdOk.FindFirst(TreeScope.Descendants, new AndCondition(rdOC3, rdOC4)); Win32.SendMessage((IntPtr)rdClickOk.Current.NativeWindowHandle, Win32.BN_CLICKED, 0, 0); } else { timerFindSecurityRDC.Start(); } } catch (Exception Ex) { } }
public void Select() { SelectionItemPattern sip = (SelectionItemPattern)treeitem.GetCurrentPattern(SelectionItemPattern.Pattern); sip.Select(); return; }
///-------------------------------------------------------------------- /// <summary> /// Mirrors target selections in client list boxes. /// </summary> /// <param name="targetSelectionControl"> /// Current target selection control. /// </param> /// <param name="controlCounter"> /// Index of current selection control. /// </param> ///-------------------------------------------------------------------- internal void EchoTargetControlSelections( AutomationElement targetSelectionControl, int controlCounter) { // Check if we need to call BeginInvoke. if (this.Dispatcher.CheckAccess() == false) { // Pass the same function to BeginInvoke, // but the call would come on the correct // thread and InvokeRequired will be false. this.Dispatcher.BeginInvoke( DispatcherPriority.Send, new EchoTargetControlSelectionsDelegate(EchoTargetControlSelections), targetSelectionControl, controlCounter); return; } AutomationElementCollection targetSelectionItems = targetHandler.GetSelectionItemsFromTarget(targetSelectionControl); for (int itemCounter = 0; itemCounter < targetSelectionItems.Count; itemCounter++) { SelectionItemPattern selectionItemPattern = targetSelectionItems[itemCounter].GetCurrentPattern( SelectionItemPattern.Pattern) as SelectionItemPattern; ListBoxItem listboxItem = GetClientItemFromIndex(clientListBox[controlCounter], itemCounter); listboxItem.IsSelected = selectionItemPattern.Current.IsSelected; } }
private void SetSelection(string option) { if ((comboBoxElement != null) && (comboBoxElement.Current.IsEnabled)) { AutomationElement sel = null; ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)comboBoxElement .GetCurrentPattern( ExpandCollapsePattern.Pattern); expandPattern.Expand(); CacheRequest cacheRequest = new CacheRequest(); cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children; AutomationElement comboboxItems = comboBoxElement.GetUpdatedCache( cacheRequest); foreach (AutomationElement item in comboboxItems.CachedChildren) { if (item.Current.Name == "") { CacheRequest cacheRequest2 = new CacheRequest(); cacheRequest2.Add(AutomationElement.NameProperty); cacheRequest2.TreeScope = TreeScope.Element | TreeScope.Children; AutomationElement comboboxItems2 = item.GetUpdatedCache(cacheRequest); foreach (AutomationElement item2 in comboboxItems2.CachedChildren) { if (item2.Current.Name == option) { sel = item2; } } } } if (sel != null) { SelectionItemPattern select = (SelectionItemPattern)sel.GetCurrentPattern( SelectionItemPattern.Pattern); select.Select(); } expandPattern.Collapse(); } SetForegroundWindow(this.Handle); }
public static void Select(this AutomationElement Control) { //check if the buttonControl is indeed a handle to a button-based control SelectionItemPattern selPattern = ValidateControlForSelectionPattern(Control); //click the button control selPattern.Select(); }
// RopModifyPermissions RopGetPermissionsTable public void ModifyFolderPermissions() { // Get account name var desktop = AutomationElement.RootElement; var nameSpace = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder folder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); string userName = folder.Parent.Name; // Get outlook window var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook"); var window_outlook = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10); // Get Folder Tab and select it Condition cd_RibbonTabs = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Folder")); AutomationElement item_RibbonTabs = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300); SelectionItemPattern Pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern); Pattern_RibbonTabs.Select(); // Get "Folder Permissions" and select it Condition cd_FolderPermissions = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Folder Permissions")); AutomationElement item_FolderPermissions = Utilities.WaitForElement(window_outlook, cd_FolderPermissions, TreeScope.Descendants, 10); InvokePattern clickPattern_FolderPermissions = (InvokePattern)item_FolderPermissions.GetCurrentPattern(InvokePattern.Pattern); clickPattern_FolderPermissions.Invoke(); // Get "Inbox Properties" window var condition_permission = new PropertyCondition(AutomationElement.NameProperty, "Inbox Properties"); var window_FolderProp = Utilities.WaitForElement(window_outlook, condition_permission, TreeScope.Children, 10); // Get and select "Create items" Condition cd_write = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox), new PropertyCondition(AutomationElement.NameProperty, "Edit all")); AutomationElement item_write = Utilities.WaitForElement(window_FolderProp, cd_write, TreeScope.Descendants, 10); TogglePattern Pattern_write = (TogglePattern)item_write.GetCurrentPattern(TogglePattern.Pattern); Pattern_write.Toggle(); // Click OK in Microsoft Outlook dialog box var condition_Dailog = new PropertyCondition(AutomationElement.NameProperty, "Microsoft Outlook"); var window_Dailog = Utilities.WaitForElement(window_FolderProp, condition_Dailog, TreeScope.Children, 10); var condition_DailogOK = new PropertyCondition(AutomationElement.AutomationIdProperty, "6"); var item_DailogOK = Utilities.WaitForElement(window_Dailog, condition_DailogOK, TreeScope.Children, 10); InvokePattern clickPattern_DailogOK = (InvokePattern)item_DailogOK.GetCurrentPattern(InvokePattern.Pattern); clickPattern_DailogOK.Invoke(); // Click OK in "Inbox Properties" window var condition_FolderPropOK = new PropertyCondition(AutomationElement.AutomationIdProperty, "1"); var item_FolderPropertyOK = Utilities.WaitForElement(window_FolderProp, condition_FolderPropOK, TreeScope.Children, 10); InvokePattern clickPattern_FolderPropertyOK = (InvokePattern)item_FolderPropertyOK.GetCurrentPattern(InvokePattern.Pattern); clickPattern_FolderPropertyOK.Invoke(); bool result = MessageParser.ParseMessage(); Assert.IsTrue(result, "Case failed, check the details information in error.txt file."); }
/// <summary> /// Create a new automation helper for the pattern /// </summary> /// <param name="element">The automation element to wrap</param> public SelectableElement(AutomationElement element) { base.element = element; pattern = Element.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; if (pattern == null) { throw new ArgumentException("Helper must represent a selectable item"); } }
// </Snippet104> // <Snippet105> void AddListItemToSelection(AutomationElement listItem) { if (listItem == null) throw new ArgumentException(); SelectionItemPattern pattern = listItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; if (pattern != null) { pattern.AddToSelection(); } }
public static void AssertSelected(AutomationElement element, bool expected) { SelectionItemPattern currentPattern = AutomationPatternHelper.GetSelectionItemPattern(element); bool isSelected = currentPattern.Current.IsSelected; if (expected != isSelected) { throw new Exception(string.Format("Selected is not as expected. Expected: {0}, Actual: {1}. ({2})", expected, isSelected, element.ToString())); } }
// </Snippet107> // <Snippet108> /// <summary> /// Caches and retrieves properties for a list item by using CacheRequest.Push. /// </summary> /// <param name="autoElement">Element from which to retrieve a child element.</param> /// <remarks> /// This code demonstrates various aspects of caching. It is not intended to be /// an example of a useful method. /// </remarks> private void CachePropertiesByPush(AutomationElement elementList) { // <Snippet183> // Set up the request. CacheRequest cacheRequest = new CacheRequest(); // Do not get a full reference to the cached objects, only to their cached properties and patterns. cacheRequest.AutomationElementMode = AutomationElementMode.None; // </Snippet183> // Cache all elements, regardless of whether they are control or content elements. cacheRequest.TreeFilter = Automation.RawViewCondition; // Property and pattern to cache. cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(SelectionItemPattern.Pattern); // Activate the request. cacheRequest.Push(); // Obtain an element and cache the requested items. Condition cond = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true); AutomationElement elementListItem = elementList.FindFirst(TreeScope.Children, cond); // At this point, you could call another method that creates a CacheRequest and calls Push/Pop. // While that method was retrieving automation elements, the CacheRequest set in this method // would not be active. // Deactivate the request. cacheRequest.Pop(); // Retrieve the cached property and pattern. String itemName = elementListItem.Cached.Name; SelectionItemPattern pattern = elementListItem.GetCachedPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; // The following is an alternative way of retrieving the Name property. itemName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty) as String; // This is yet another way, which returns AutomationElement.NotSupported if the element does // not supply a value. If the second parameter is false, a default name is returned. object objName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, true); if (objName == AutomationElement.NotSupported) { itemName = "Unknown"; } else { itemName = objName as String; } // The following call raises an exception, because only the cached properties are available, // as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its // default value (Full), this call would be valid. /*** bool enabled = elementListItem.Current.IsEnabled; ***/ }
public void RemoveFromSelection(bool log) { if (log) { procedureLogger.Action(string.Format("Unselect {0}.", this.NameAndType)); } SelectionItemPattern sip = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern); sip.RemoveFromSelection(); }
public void MenuItemAutomationSelectionTest() { var testScenarios = RegressionTestScenario.BuildAllRegressionTestScenarios(); foreach (var testScenario in testScenarios) { using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", testScenario.TestPageName })) { UIObject firstItem = FindElement.ByName("Home"); UIObject secondItem = FindElement.ByName("Apps"); UIObject thirdItem = FindElement.ByName("Games"); Log.Comment("Verify the second item is not already selected"); Verify.IsFalse(Convert.ToBoolean(secondItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected")))); firstItem.SetFocus(); AutomationElement firstItemAE = AutomationElement.FocusedElement; SelectionItemPattern firstItemSIP = firstItemAE.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; Log.Comment("Move focus to the second item by pressing down(left nav)/right(right nav) arrow once"); var key = Key.Right; if (testScenario.IsLeftNavTest) { key = Key.Down; } KeyboardHelper.PressKey(key); Wait.ForIdle(); Verify.IsTrue(secondItem.HasKeyboardFocus); AutomationElement secondItemAE = AutomationElement.FocusedElement; SelectionItemPattern secondItemSIP = secondItemAE.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; Log.Comment("Select the second item using SelectionItemPattern.Select and verify"); secondItemSIP.Select(); Wait.ForIdle(); Verify.IsTrue(Convert.ToBoolean(secondItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected")))); Log.Comment("Deselect the second item"); firstItemSIP.Select(); Wait.ForIdle(); Verify.IsTrue(Convert.ToBoolean(firstItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected")))); Log.Comment("Select the second item using SelectionItemPattern.AddToSelection and verify"); secondItemSIP.AddToSelection(); Wait.ForIdle(); Verify.IsTrue(Convert.ToBoolean(secondItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected")))); ClickClearSelectionButton(); Log.Comment("second item is unselected"); Verify.IsFalse(Convert.ToBoolean(secondItem.GetProperty(UIProperty.Get("SelectionItem.IsSelected")))); } } }
public void RemoveFromSelection() { SelectionItemPattern vp = e.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; if (vp != null) { vp.RemoveFromSelection(); return; } throw new Exception("Element does not support SelectionItemPattern"); }
private void enterMeasureTab() { System.Windows.Automation.Condition textConditionOne = new PropertyCondition(AutomationElement.AutomationIdProperty, "TabControl_SelectOperationMode"); AutomationElement textOne = testWindow.FindFirst(TreeScope.Descendants, textConditionOne); textOne.SetFocus(); AutomationElement aeTabPage = textOne.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "MEASURE")); SelectionItemPattern valuetextOne = aeTabPage.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; valuetextOne.Select(); }